mirror of
				https://github.com/Mibew/handlebars.php.git
				synced 2025-10-31 02:15:50 +03:00 
			
		
		
		
	
							parent
							
								
									65fe447c36
								
							
						
					
					
						commit
						89f0c00790
					
				| @ -40,21 +40,31 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader | |||||||
|      * Passing an $options array allows overriding certain Loader options during instantiation: |      * Passing an $options array allows overriding certain Loader options during instantiation: | ||||||
|      * |      * | ||||||
|      *     $options = array( |      *     $options = array( | ||||||
|      *         // The filename extension used for Mustache templates. Defaults to '.mustache'
 |      *         // The filename extension used for Handlebars templates. Defaults to '.handlebars'
 | ||||||
|      *         'extension' => '.ms', |      *         'extension' => '.other', | ||||||
|      *     ); |      *     ); | ||||||
|      * |      * | ||||||
|      * @param string $baseDir Base directory containing Mustache template files. |      * @param string|array $baseDirs A path contain template files or array of paths | ||||||
|      * @param array        $options  Array of Loader options (default: array()) |      * @param array        $options  Array of Loader options (default: array()) | ||||||
|      * |      * | ||||||
|      * @throws RuntimeException if $baseDir does not exist. |      * @throws RuntimeException if $baseDir does not exist. | ||||||
|      */ |      */ | ||||||
|     public function __construct($baseDir, array $options = array()) |     public function __construct($baseDirs, array $options = array()) | ||||||
|     { |     { | ||||||
|         $this->_baseDir = rtrim(realpath($baseDir), '/'); |         if (is_string($baseDir)) { | ||||||
|  |             $baseDir = array(rtrim(realpath($baseDir), '/')); | ||||||
|  |         } else { | ||||||
|  |             foreach ($baseDir as &$dir) { | ||||||
|  |                 $dir = array(rtrim(realpath($dir), '/')); | ||||||
|  |             } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         if (!is_dir($this->_baseDir)) { |         $this->_baseDir = $baseDir; | ||||||
|             throw new RuntimeException('FilesystemLoader baseDir must be a directory: '.$baseDir); | 
 | ||||||
|  |         foreach ($this->_baseDir as $dir) { | ||||||
|  |             if (!is_dir($dir)) { | ||||||
|  |                 throw new RuntimeException('FilesystemLoader baseDir must be a directory: ' . $dir); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (isset($options['extension'])) { |         if (isset($options['extension'])) { | ||||||
| @ -70,11 +80,11 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader | |||||||
|      * Load a Template by name. |      * Load a Template by name. | ||||||
|      * |      * | ||||||
|      *     $loader = new FilesystemLoader(dirname(__FILE__).'/views'); |      *     $loader = new FilesystemLoader(dirname(__FILE__).'/views'); | ||||||
|      *     $loader->load('admin/dashboard'); // loads "./views/admin/dashboard.mustache";
 |      *     $loader->load('admin/dashboard'); // loads "./views/admin/dashboard.handlebars";
 | ||||||
|      * |      * | ||||||
|      * @param string $name template name |      * @param string $name template name | ||||||
|      * |      * | ||||||
|      * @return string Handkebars Template source |      * @return string Handlebars Template source | ||||||
|      */ |      */ | ||||||
|     public function load($name) |     public function load($name) | ||||||
|     { |     { | ||||||
| @ -86,26 +96,26 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Helper function for loading a Mustache file by name. |      * Helper function for loading a Handlebars file by name. | ||||||
|      * |      * | ||||||
|      * @param string $name template name |      * @param string $name template name | ||||||
|      * |      * | ||||||
|      * @return string Mustache Template source |      * @return string Handlebars Template source | ||||||
|      * @throws InvalidArgumentException if a template file is not found. |      * @throws InvalidArgumentException if a template file is not found. | ||||||
|      */ |      */ | ||||||
|     protected function loadFile($name) |     protected function loadFile($name) | ||||||
|     { |     { | ||||||
|         $fileName = $this->getFileName($name); |         $fileName = $this->getFileName($name); | ||||||
| 
 | 
 | ||||||
|         if (!file_exists($fileName)) { |         if ($fileName === false) { | ||||||
|             throw new InvalidArgumentException('Template '.$name.' not found.'); |             throw new InvalidArgumentException('Template ' . $name . ' not found.'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return file_get_contents($fileName); |         return file_get_contents($fileName); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Helper function for getting a Mustache template file name. |      * Helper function for getting a Handlebars template file name. | ||||||
|      * |      * | ||||||
|      * @param string $name template name |      * @param string $name template name | ||||||
|      * |      * | ||||||
| @ -113,11 +123,12 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader | |||||||
|      */ |      */ | ||||||
|     protected function getFileName($name) |     protected function getFileName($name) | ||||||
|     { |     { | ||||||
|         $fileName = $this->_baseDir . '/'; |         foreach ($this->_baseDir as $baseDir) { | ||||||
|  |             $fileName = $baseDir . '/'; | ||||||
|             $fileParts = explode('/', $name); |             $fileParts = explode('/', $name); | ||||||
|             $file = array_pop($fileParts); |             $file = array_pop($fileParts); | ||||||
| 
 | 
 | ||||||
|         if (substr($file, strlen($this->_prefix)) !== $this->_prefix){ |             if (substr($file, strlen($this->_prefix)) !== $this->_prefix) { | ||||||
|                 $file = $this->_prefix . $file; |                 $file = $this->_prefix . $file; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| @ -127,7 +138,11 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader | |||||||
|             if (substr($fileName, 0 - strlen($this->_extension)) !== $this->_extension) { |             if (substr($fileName, 0 - strlen($this->_extension)) !== $this->_extension) { | ||||||
|                 $fileName .= $this->_extension; |                 $fileName .= $this->_extension; | ||||||
|             } |             } | ||||||
| 
 |             if (file_exists($fileName)) { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |             $fileName = false; | ||||||
|  |         } | ||||||
|         return $fileName; |         return $fileName; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user