1 | <?php |
||
10 | final class FilesystemLoader implements Twig_LoaderInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | private $path; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $fileExtensions = ['html.twig', 'twig']; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $cache = []; |
||
26 | |||
27 | 6 | public function __construct(string $path, array $fileExtensions = null) |
|
28 | { |
||
29 | 6 | $this->path = $path; |
|
30 | |||
31 | 6 | if ($fileExtensions) { |
|
32 | 2 | $this->fileExtensions = $fileExtensions; |
|
33 | } |
||
34 | 6 | } |
|
35 | |||
36 | /** |
||
37 | * @inheritDoc |
||
38 | */ |
||
39 | 4 | public function getSourceContext($name) |
|
40 | { |
||
41 | 4 | $code = file_get_contents($this->template($name)); |
|
42 | |||
43 | 3 | return new Twig_Source($code, $name); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @inheritDoc |
||
48 | */ |
||
49 | 1 | public function getCacheKey($name) |
|
53 | |||
54 | /** |
||
55 | * @inheritDoc |
||
56 | */ |
||
57 | 1 | public function isFresh($name, $time) |
|
61 | |||
62 | /** |
||
63 | * @inheritDoc |
||
64 | */ |
||
65 | 1 | public function exists($name) |
|
73 | |||
74 | /** |
||
75 | * @param string $name |
||
76 | * |
||
77 | * @return string |
||
78 | * |
||
79 | * @throws LoaderException |
||
80 | * When $name is not found. |
||
81 | */ |
||
82 | 5 | private function template($name) |
|
95 | |||
96 | /** |
||
97 | * @param string $name |
||
98 | * |
||
99 | * @return string|null |
||
100 | */ |
||
101 | 5 | private function findTemplate($name) |
|
114 | |||
115 | /** |
||
116 | * @param string $name |
||
117 | * |
||
118 | * @return Generator |
||
119 | */ |
||
120 | 5 | private function possibleTemplateFiles($name) |
|
128 | |||
129 | /** |
||
130 | * @param string $name |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | 5 | private function normalizeName($name) |
|
141 | } |
||
142 |