| @@ -1,78 +1,78 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/* | |
| 4 | - * This file is part of Mustache.php. | |
| 5 | - * | |
| 6 | - * (c) 2012 Justin Hileman | |
| 7 | - * | |
| 8 | - * For the full copyright and license information, please view the LICENSE | |
| 9 | - * file that was distributed with this source code. | |
| 10 | - */ | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * Mustache Template array Loader implementation. | |
| 14 | - * | |
| 15 | - * An ArrayLoader instance loads Mustache Template source by name from an initial array: | |
| 16 | - * | |
| 17 | - * $loader = new ArrayLoader( | |
| 18 | - * 'foo' => '{{ bar }}', | |
| 19 | - * 'baz' => 'Hey {{ qux }}!' | |
| 20 | - * ); | |
| 21 | - * | |
| 22 | - * $tpl = $loader->load('foo'); // '{{ bar }}' | |
| 23 | - * | |
| 24 | - * The ArrayLoader is used internally as a partials loader by Mustache_Engine instance when an array of partials | |
| 25 | - * is set. It can also be used as a quick-and-dirty Template loader. | |
| 26 | - */ | |
| 27 | -class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_MutableLoader | |
| 28 | -{ | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * ArrayLoader constructor. | |
| 32 | - * | |
| 33 | - * @param array $templates Associative array of Template source (default: array()) | |
| 34 | - */ | |
| 35 | - public function __construct(array $templates = array()) | |
| 36 | - { | |
| 37 | - $this->templates = $templates; | |
| 38 | - } | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * Load a Template. | |
| 42 | - * | |
| 43 | - * @throws Mustache_Exception_UnknownTemplateException If a template file is not found. | |
| 44 | - * | |
| 45 | - * @param string $name | |
| 46 | - * | |
| 47 | - * @return string Mustache Template source | |
| 48 | - */ | |
| 49 | - public function load($name) | |
| 50 | - { | |
| 51 | - if (!isset($this->templates[$name])) { | |
| 52 | - throw new Mustache_Exception_UnknownTemplateException($name); | |
| 53 | - } | |
| 54 | - | |
| 55 | - return $this->templates[$name]; | |
| 56 | - } | |
| 57 | - | |
| 58 | - /** | |
| 59 | - * Set an associative array of Template sources for this loader. | |
| 60 | - * | |
| 61 | - * @param array $templates | |
| 62 | - */ | |
| 63 | - public function setTemplates(array $templates) | |
| 64 | - { | |
| 65 | - $this->templates = $templates; | |
| 66 | - } | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * Set a Template source by name. | |
| 70 | - * | |
| 71 | - * @param string $name | |
| 72 | - * @param string $template Mustache Template source | |
| 73 | - */ | |
| 74 | - public function setTemplate($name, $template) | |
| 75 | - { | |
| 76 | - $this->templates[$name] = $template; | |
| 77 | - } | |
| 78 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/* | |
| 4 | + * This file is part of Mustache.php. | |
| 5 | + * | |
| 6 | + * (c) 2012 Justin Hileman | |
| 7 | + * | |
| 8 | + * For the full copyright and license information, please view the LICENSE | |
| 9 | + * file that was distributed with this source code. | |
| 10 | + */ | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Mustache Template array Loader implementation. | |
| 14 | + * | |
| 15 | + * An ArrayLoader instance loads Mustache Template source by name from an initial array: | |
| 16 | + * | |
| 17 | + * $loader = new ArrayLoader( | |
| 18 | + * 'foo' => '{{ bar }}', | |
| 19 | + * 'baz' => 'Hey {{ qux }}!' | |
| 20 | + * ); | |
| 21 | + * | |
| 22 | + * $tpl = $loader->load('foo'); // '{{ bar }}' | |
| 23 | + * | |
| 24 | + * The ArrayLoader is used internally as a partials loader by Mustache_Engine instance when an array of partials | |
| 25 | + * is set. It can also be used as a quick-and-dirty Template loader. | |
| 26 | + */ | |
| 27 | +class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_MutableLoader | |
| 28 | +{ | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * ArrayLoader constructor. | |
| 32 | + * | |
| 33 | + * @param array $templates Associative array of Template source (default: array()) | |
| 34 | + */ | |
| 35 | + public function __construct(array $templates = array()) | |
| 36 | + { | |
| 37 | + $this->templates = $templates; | |
| 38 | + } | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Load a Template. | |
| 42 | + * | |
| 43 | + * @throws Mustache_Exception_UnknownTemplateException If a template file is not found. | |
| 44 | + * | |
| 45 | + * @param string $name | |
| 46 | + * | |
| 47 | + * @return string Mustache Template source | |
| 48 | + */ | |
| 49 | + public function load($name) | |
| 50 | + { | |
| 51 | + if (!isset($this->templates[$name])) { | |
| 52 | + throw new Mustache_Exception_UnknownTemplateException($name); | |
| 53 | + } | |
| 54 | + | |
| 55 | + return $this->templates[$name]; | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Set an associative array of Template sources for this loader. | |
| 60 | + * | |
| 61 | + * @param array $templates | |
| 62 | + */ | |
| 63 | + public function setTemplates(array $templates) | |
| 64 | + { | |
| 65 | + $this->templates = $templates; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Set a Template source by name. | |
| 70 | + * | |
| 71 | + * @param string $name | |
| 72 | + * @param string $template Mustache Template source | |
| 73 | + */ | |
| 74 | + public function setTemplate($name, $template) | |
| 75 | + { | |
| 76 | + $this->templates[$name] = $template; | |
| 77 | + } | |
| 78 | +} | |