1 | <?php |
||
9 | final class FilesystemLoader implements TwigLoader, TwigExistsLoader |
||
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 | 6 | public function __construct( |
|
37 | |||
38 | /** |
||
39 | * @inheritDoc |
||
40 | */ |
||
41 | 4 | public function getSource($name) |
|
45 | |||
46 | /** |
||
47 | * @inheritDoc |
||
48 | */ |
||
49 | public function getCacheKey($name) |
||
50 | { |
||
51 | return $this->template($name); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @inheritDoc |
||
56 | */ |
||
57 | 1 | public function isFresh($name, $time) |
|
61 | |||
62 | /** |
||
63 | * @inheritDoc |
||
64 | */ |
||
65 | 1 | public function exists($name) |
|
66 | { |
||
67 | 1 | if (isset($this->cache[$name])) { |
|
68 | return true; |
||
69 | } |
||
70 | |||
71 | 1 | return (bool) $this->findTemplate($name); |
|
72 | } |
||
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) |
|
83 | { |
||
84 | 5 | if (isset($this->cache[$name])) { |
|
85 | return $this->cache[$name]; |
||
86 | } |
||
87 | |||
88 | 5 | $found = $this->findTemplate($name); |
|
89 | 5 | if (null !== $found) { |
|
90 | 4 | throw LoaderException::notFound($name, $this->path); |
|
91 | } |
||
92 | |||
93 | 1 | return $this->cache[$name] = $found; |
|
94 | } |
||
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 array |
||
119 | */ |
||
120 | 5 | private function possibleTemplateFiles($name) |
|
131 | |||
132 | /** |
||
133 | * @param string $name |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | 5 | private function normalizeName($name) |
|
143 | } |
||
144 |