1 | <?php |
||
9 | final class FilesystemLoader implements Twig_LoaderInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $path; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | private $fileExtensions = []; |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | private $cache = []; |
||
25 | |||
26 | /** |
||
27 | * @param string $path The template directory path |
||
28 | * @param array $fileExtensions The template file extensions |
||
29 | */ |
||
30 | 8 | public function __construct($path, array $fileExtensions = []) |
|
31 | { |
||
32 | 8 | $this->path = $path; |
|
33 | 8 | $this->fileExtensions = $fileExtensions; |
|
34 | 8 | } |
|
35 | |||
36 | /** |
||
37 | * For Twig 1.x compatibility. |
||
38 | */ |
||
39 | 1 | public function getSource($name) |
|
40 | { |
||
41 | 1 | return file_get_contents($this->template($name)); |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * @inheritDoc |
||
46 | */ |
||
47 | 4 | public function getSourceContext($name) |
|
48 | { |
||
49 | 4 | $code = file_get_contents($this->template($name)); |
|
50 | |||
51 | 3 | return new Twig_Source($code, $name); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * @inheritDoc |
||
56 | */ |
||
57 | 1 | public function getCacheKey($name) |
|
61 | |||
62 | /** |
||
63 | * @inheritDoc |
||
64 | */ |
||
65 | 1 | public function isFresh($name, $time) |
|
69 | |||
70 | /** |
||
71 | * @inheritDoc |
||
72 | */ |
||
73 | 1 | public function exists($name) |
|
81 | |||
82 | /** |
||
83 | * @param string $name |
||
84 | * |
||
85 | * @return string |
||
86 | * |
||
87 | * @throws LoaderException |
||
88 | * When $name is not found. |
||
89 | */ |
||
90 | 6 | private function template($name) |
|
103 | |||
104 | /** |
||
105 | * @param string $name |
||
106 | * |
||
107 | * @return string|null |
||
108 | */ |
||
109 | 6 | private function findTemplate($name) |
|
122 | |||
123 | /** |
||
124 | * @param string $name |
||
125 | * |
||
126 | * @return Generator |
||
127 | */ |
||
128 | 6 | private function possibleTemplateFiles($name) |
|
136 | |||
137 | /** |
||
138 | * @param string $name |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | 6 | private function normalizeName($name) |
|
149 | } |
||
150 |