PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.1.12
Responsive Menu – Create Mobile-Friendly Menu v3.1.12
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / vendor / twig / twig / lib / Twig / Loader / Array.php

Array.php in Responsive Menu – Create Mobile-Friendly Menu 3.1.12, at vendor/twig/twig/lib/Twig/Loader/Array.php

96 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
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 * Loads a template from an array.
14 *
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.
19 *
20 * This loader should only be used for unit testing.
21 *
22 * @final
23 *
24 * @author Fabien Potencier <fabien@symfony.com>
25 */
26 class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
27 {
28 protected $templates = array();
29
30 /**
31 * @param array $templates An array of templates (keys are the names, and values are the source code)
32 */
33 public function __construct(array $templates = array())
34 {
35 $this->templates = $templates;
36 }
37
38 /**
39 * Adds or overrides a template.
40 *
41 * @param string $name The template name
42 * @param string $template The template source
43 */
44 public function setTemplate($name, $template)
45 {
46 $this->templates[(string) $name] = $template;
47 }
48
49 public function getSource($name)
50 {
51 @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
52
53 $name = (string) $name;
54 if (!isset($this->templates[$name])) {
55 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
56 }
57
58 return $this->templates[$name];
59 }
60
61 public function getSourceContext($name)
62 {
63 $name = (string) $name;
64 if (!isset($this->templates[$name])) {
65 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
66 }
67
68 return new Twig_Source($this->templates[$name], $name);
69 }
70
71 public function exists($name)
72 {
73 return isset($this->templates[(string) $name]);
74 }
75
76 public function getCacheKey($name)
77 {
78 $name = (string) $name;
79 if (!isset($this->templates[$name])) {
80 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
81 }
82
83 return $this->templates[$name];
84 }
85
86 public function isFresh($name, $time)
87 {
88 $name = (string) $name;
89 if (!isset($this->templates[$name])) {
90 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
91 }
92
93 return true;
94 }
95 }
96