1 | <?php |
||
14 | class FilesystemLoader |
||
15 | { |
||
16 | /** Identifier of the main namespace. */ |
||
17 | const MAIN_NAMESPACE = '__main__'; |
||
18 | |||
19 | protected $locator; |
||
20 | protected $parser; |
||
21 | |||
22 | protected $paths = []; |
||
23 | protected $cache = []; |
||
24 | protected $errorCache = []; |
||
25 | |||
26 | /** |
||
27 | * FilesystemLoader constructor. |
||
28 | * @param FileLocatorInterface $locator |
||
29 | * @param TemplateNameParserInterface $parser |
||
30 | */ |
||
31 | 25 | public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser) |
|
37 | |||
38 | /** |
||
39 | * Returns the paths to the templates. |
||
40 | * |
||
41 | * @param string $namespace A path namespace |
||
42 | * |
||
43 | * @return array The array of paths where to look for templates |
||
44 | */ |
||
45 | 7 | public function getPaths($namespace = self::MAIN_NAMESPACE) |
|
49 | |||
50 | /** |
||
51 | * Returns the path namespaces. |
||
52 | * |
||
53 | * The main namespace is always defined. |
||
54 | * |
||
55 | * @return array The array of defined namespaces |
||
56 | */ |
||
57 | 1 | public function getNamespaces() |
|
61 | |||
62 | /** |
||
63 | * Sets the paths where templates are stored. |
||
64 | * |
||
65 | * @param string|array $paths A path or an array of paths where to look for templates |
||
66 | * @param string $namespace A path namespace |
||
67 | */ |
||
68 | 25 | public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) |
|
79 | |||
80 | /** |
||
81 | * Adds a path where templates are stored. |
||
82 | * |
||
83 | * @param string $path A path where to look for templates |
||
84 | * @param string $namespace A path name |
||
85 | * |
||
86 | * @throws LoaderException |
||
87 | */ |
||
88 | 20 | public function addPath($path, $namespace = self::MAIN_NAMESPACE) |
|
99 | |||
100 | /** |
||
101 | * Prepends a path where templates are stored. |
||
102 | * |
||
103 | * @param string $path A path where to look for templates |
||
104 | * @param string $namespace A path name |
||
105 | * |
||
106 | * @throws LoaderException |
||
107 | */ |
||
108 | 3 | public function prependPath($path, $namespace = self::MAIN_NAMESPACE) |
|
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | 7 | public function getSource($name) |
|
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | 4 | public function getCacheKey($name) |
|
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | 7 | public function exists($template) |
|
159 | |||
160 | 14 | protected function parseName($name, $default = self::MAIN_NAMESPACE) |
|
175 | |||
176 | 14 | protected function normalizeName($name) |
|
180 | |||
181 | 14 | protected function findTemplate($template, $throw = true) |
|
198 | |||
199 | 10 | private function searchTemplate($template, $name, $shortName, $namespace, $throw) { |
|
216 | |||
217 | 12 | private function validateTemplate($name, $namespace) |
|
231 | |||
232 | 9 | private function locateTemplate($template, $name, $namespace) |
|
251 | } |
||
252 |