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 {
69  if ($loader instanceof Twig_SourceContextLoaderInterface) {
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 {
100  if ($loader instanceof Twig_SourceContextLoaderInterface) {
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 
151 class_alias('Twig_Loader_Chain', 'Twig\Loader\ChainLoader', false);
Add rich text string
exists($name)
Check if we have the source code of a template, given its name.
__construct(array $loaders=array())
Definition: Chain.php:27
addLoader(Twig_LoaderInterface $loader)
Definition: Chain.php:34
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
getCacheKey($name)
Gets the cache key to use for the cache for a given template name.
Definition: Chain.php:114
$time
Definition: cron.php:21
if($format !==null) $name
Definition: metadata.php:146
Adds an exists() method for loaders.
Adds a getSourceContext() method for loaders.
exists($name)
Check if we have the source code of a template, given its name.
Definition: Chain.php:82
Loads templates from other loaders.
Definition: Chain.php:19
Create styles array
The data for the language used.
getSourceContext($name)
Returns the source context for a given template logical name.
Definition: Chain.php:60
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Interface all loaders must implement.
$exceptions
Definition: Utf8Test.php:67
isFresh($name, $time)
Returns true if the template is still fresh.
Definition: Chain.php:132
getSource($name)
Gets the source code of a template, given its name.
Definition: Chain.php:40