ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Chain.php
Go to the documentation of this file.
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
20{
21 private $hasSourceCache = array();
22 protected $loaders = array();
23
27 public function __construct(array $loaders = array())
28 {
29 foreach ($loaders as $loader) {
30 $this->addLoader($loader);
31 }
32 }
33
35 {
36 $this->loaders[] = $loader;
37 $this->hasSourceCache = array();
38 }
39
40 public function getSource($name)
41 {
42 @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
43
44 $exceptions = array();
45 foreach ($this->loaders as $loader) {
46 if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
47 continue;
48 }
49
50 try {
51 return $loader->getSource($name);
52 } catch (Twig_Error_Loader $e) {
53 $exceptions[] = $e->getMessage();
54 }
55 }
56
57 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
58 }
59
60 public function getSourceContext($name)
61 {
62 $exceptions = array();
63 foreach ($this->loaders as $loader) {
64 if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
65 continue;
66 }
67
68 try {
70 return $loader->getSourceContext($name);
71 }
72
73 return new Twig_Source($loader->getSource($name), $name);
74 } catch (Twig_Error_Loader $e) {
75 $exceptions[] = $e->getMessage();
76 }
77 }
78
79 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
80 }
81
82 public function exists($name)
83 {
84 $name = (string) $name;
85
86 if (isset($this->hasSourceCache[$name])) {
87 return $this->hasSourceCache[$name];
88 }
89
90 foreach ($this->loaders as $loader) {
91 if ($loader instanceof Twig_ExistsLoaderInterface) {
92 if ($loader->exists($name)) {
93 return $this->hasSourceCache[$name] = true;
94 }
95
96 continue;
97 }
98
99 try {
101 $loader->getSourceContext($name);
102 } else {
103 $loader->getSource($name);
104 }
105
106 return $this->hasSourceCache[$name] = true;
107 } catch (Twig_Error_Loader $e) {
108 }
109 }
110
111 return $this->hasSourceCache[$name] = false;
112 }
113
114 public function getCacheKey($name)
115 {
116 $exceptions = array();
117 foreach ($this->loaders as $loader) {
118 if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
119 continue;
120 }
121
122 try {
123 return $loader->getCacheKey($name);
124 } catch (Twig_Error_Loader $e) {
125 $exceptions[] = get_class($loader).': '.$e->getMessage();
126 }
127 }
128
129 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
130 }
131
132 public function isFresh($name, $time)
133 {
134 $exceptions = array();
135 foreach ($this->loaders as $loader) {
136 if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
137 continue;
138 }
139
140 try {
141 return $loader->isFresh($name, $time);
142 } catch (Twig_Error_Loader $e) {
143 $exceptions[] = get_class($loader).': '.$e->getMessage();
144 }
145 }
146
147 throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
148 }
149}
150
151class_alias('Twig_Loader_Chain', 'Twig\Loader\ChainLoader', false);
sprintf('%.4f', $callTime)
$exceptions
Definition: Utf8Test.php:67
An exception for terminatinating execution or to throw for unit testing.
Exception thrown when an error occurs during template loading.
Definition: Loader.php:26
Loads templates from other loaders.
Definition: Chain.php:20
getSourceContext($name)
Returns the source context for a given template logical name.
Definition: Chain.php:60
addLoader(Twig_LoaderInterface $loader)
Definition: Chain.php:34
__construct(array $loaders=array())
Definition: Chain.php:27
getCacheKey($name)
Gets the cache key to use for the cache for a given template name.
Definition: Chain.php:114
isFresh($name, $time)
Returns true if the template is still fresh.
Definition: Chain.php:132
exists($name)
Check if we have the source code of a template, given its name.
Definition: Chain.php:82
getSource($name)
Gets the source code of a template, given its name.
Definition: Chain.php:40
Holds information about a non-compiled Twig template.
Definition: Source.php:20
Adds an exists() method for loaders.
Interface all loaders must implement.
Adds a getSourceContext() method for loaders.
$time
Definition: cron.php:21
if($format !==null) $name
Definition: metadata.php:146