diff options
author | Simon Rettberg | 2023-10-06 18:26:22 +0200 |
---|---|---|
committer | Simon Rettberg | 2023-10-06 18:26:22 +0200 |
commit | e5be4e97ffc41ca3b0386651a626b781a3637a85 (patch) | |
tree | 20152d35607de272edae44725efba13f21da85a1 /Mustache/Loader/CascadingLoader.php | |
parent | api: Hard-code bogus name/mail for read only (STUDENT) login (diff) | |
download | bwlp-webadmin-e5be4e97ffc41ca3b0386651a626b781a3637a85.tar.gz bwlp-webadmin-e5be4e97ffc41ca3b0386651a626b781a3637a85.tar.xz bwlp-webadmin-e5be4e97ffc41ca3b0386651a626b781a3637a85.zip |
Update for PHP 8.2
Diffstat (limited to 'Mustache/Loader/CascadingLoader.php')
-rw-r--r-- | Mustache/Loader/CascadingLoader.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Mustache/Loader/CascadingLoader.php b/Mustache/Loader/CascadingLoader.php new file mode 100644 index 0000000..3fb6353 --- /dev/null +++ b/Mustache/Loader/CascadingLoader.php @@ -0,0 +1,69 @@ +<?php + +/* + * This file is part of Mustache.php. + * + * (c) 2010-2017 Justin Hileman + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * A Mustache Template cascading loader implementation, which delegates to other + * Loader instances. + */ +class Mustache_Loader_CascadingLoader implements Mustache_Loader +{ + private $loaders; + + /** + * Construct a CascadingLoader with an array of loaders. + * + * $loader = new Mustache_Loader_CascadingLoader(array( + * new Mustache_Loader_InlineLoader(__FILE__, __COMPILER_HALT_OFFSET__), + * new Mustache_Loader_FilesystemLoader(__DIR__.'/templates') + * )); + * + * @param Mustache_Loader[] $loaders + */ + public function __construct(array $loaders = array()) + { + $this->loaders = array(); + foreach ($loaders as $loader) { + $this->addLoader($loader); + } + } + + /** + * Add a Loader instance. + * + * @param Mustache_Loader $loader + */ + public function addLoader(Mustache_Loader $loader) + { + $this->loaders[] = $loader; + } + + /** + * Load a Template by name. + * + * @throws Mustache_Exception_UnknownTemplateException If a template file is not found + * + * @param string $name + * + * @return string Mustache Template source + */ + public function load($name) + { + foreach ($this->loaders as $loader) { + try { + return $loader->load($name); + } catch (Mustache_Exception_UnknownTemplateException $e) { + // do nothing, check the next loader. + } + } + + throw new Mustache_Exception_UnknownTemplateException($name); + } +} |