Security update to Drupal 8.4.6
[yaffs-website] / vendor / twig / twig / lib / Twig / Loader / Chain.php
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 templates from other loaders.
14  *
15  * @final
16  *
17  * @author Fabien Potencier <fabien@symfony.com>
18  */
19 class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
20 {
21     private $hasSourceCache = array();
22     protected $loaders = array();
23
24     /**
25      * @param Twig_LoaderInterface[] $loaders
26      */
27     public function __construct(array $loaders = array())
28     {
29         foreach ($loaders as $loader) {
30             $this->addLoader($loader);
31         }
32     }
33
34     public function addLoader(Twig_LoaderInterface $loader)
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);