composer package updates
[openemr.git] / vendor / twig / twig / lib / Twig / Loader / Array.php
blob0aac76900fc5bcc40094dee6b1515d642637fafa
1 <?php
3 /*
4 * This file is part of Twig.
6 * (c) Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 /**
13 * Loads a template from an array.
15 * When using this loader with a cache mechanism, you should know that a new cache
16 * key is generated each time a template content "changes" (the cache key being the
17 * source code of the template). If you don't want to see your cache grows out of
18 * control, you need to take care of clearing the old cache file by yourself.
20 * This loader should only be used for unit testing.
22 * @final
24 * @author Fabien Potencier <fabien@symfony.com>
26 class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
28 protected $templates = array();
30 /**
31 * @param array $templates An array of templates (keys are the names, and values are the source code)
33 public function __construct(array $templates = array())
35 $this->templates = $templates;
38 /**
39 * Adds or overrides a template.
41 * @param string $name The template name
42 * @param string $template The template source
44 public function setTemplate($name, $template)
46 $this->templates[(string) $name] = $template;
49 public function getSource($name)
51 @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
53 $name = (string) $name;
54 if (!isset($this->templates[$name])) {
55 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
58 return $this->templates[$name];
61 public function getSourceContext($name)
63 $name = (string) $name;
64 if (!isset($this->templates[$name])) {
65 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
68 return new Twig_Source($this->templates[$name], $name);
71 public function exists($name)
73 return isset($this->templates[(string) $name]);
76 public function getCacheKey($name)
78 $name = (string) $name;
79 if (!isset($this->templates[$name])) {
80 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
83 return $name.':'.$this->templates[$name];
86 public function isFresh($name, $time)
88 $name = (string) $name;
89 if (!isset($this->templates[$name])) {
90 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
93 return true;
97 class_alias('Twig_Loader_Array', 'Twig\Loader\ArrayLoader', false);