1 | <?php |
||
25 | class FileLoader extends Component implements LoaderInterface |
||
26 | { |
||
27 | use BenchmarkTrait; |
||
28 | |||
29 | /** |
||
30 | * View cache. Can be improved using MemoryInterface. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | private $sourceCache = []; |
||
35 | |||
36 | /** |
||
37 | * Such extensions will automatically be added to every file but only if no other extension |
||
38 | * specified in view name. As result you are able to render "home" view, instead of "home.twig". |
||
39 | * |
||
40 | * @var string|null |
||
41 | */ |
||
42 | protected $extension = null; |
||
43 | |||
44 | /** |
||
45 | * Available view namespaces associated with their directories. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $namespaces = []; |
||
50 | |||
51 | /** |
||
52 | * @var FilesInterface |
||
53 | */ |
||
54 | protected $files = null; |
||
55 | |||
56 | /** |
||
57 | * @param array $namespaces |
||
58 | * @param FilesInterface $files |
||
59 | */ |
||
60 | public function __construct(array $namespaces, FilesInterface $files) |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function getNamespaces(): array |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function withExtension(string $extension = null): LoaderInterface |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public function getSource(string $path): ViewSource |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function exists(string $path): bool |
||
138 | |||
139 | /** |
||
140 | * Fetch namespace and filename from view name or force default values. |
||
141 | * |
||
142 | * @param string $path |
||
143 | * |
||
144 | * @return array |
||
145 | * @throws LoaderException |
||
146 | */ |
||
147 | protected function parsePath(string $path): array |
||
183 | |||
184 | /** |
||
185 | * Make sure view filename is OK. Same as in twig. |
||
186 | * |
||
187 | * @param string $name |
||
188 | * |
||
189 | * @throws LoaderException |
||
190 | */ |
||
191 | protected function validatePath(string $name) |
||
215 | |||
216 | /** |
||
217 | * Flushing loading cache. |
||
218 | * |
||
219 | * @return self |
||
220 | */ |
||
221 | protected function flushCache(): FileLoader |
||
227 | |||
228 | /** |
||
229 | * Resolve view name based on filename (depends on current extension settings). |
||
230 | * |
||
231 | * @param string $filename |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | private function fetchName(string $filename): string |
||
243 | } |