1 | <?php |
||
19 | abstract class AbstractLoader implements |
||
20 | LoggerAwareInterface, |
||
21 | LoaderInterface |
||
22 | { |
||
23 | use LoggerAwareTrait; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $basePath = ''; |
||
29 | |||
30 | /** |
||
31 | * @var string[] |
||
32 | */ |
||
33 | private $paths = []; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | private $dynamicTemplates = []; |
||
39 | |||
40 | /** |
||
41 | * Default constructor, if none is provided by the concrete class implementations. |
||
42 | * |
||
43 | * ## Required dependencies |
||
44 | * - `logger` A PSR-3 logger |
||
45 | * |
||
46 | * @param array $data The class dependencies map. |
||
47 | */ |
||
48 | public function __construct(array $data = null) |
||
54 | |||
55 | /** |
||
56 | * Load a template content |
||
57 | * |
||
58 | * @param string $ident The template ident to load and render. |
||
59 | * @throws InvalidArgumentException If the dynamic template identifier is not a string. |
||
60 | * @return string |
||
61 | */ |
||
62 | public function load($ident) |
||
84 | |||
85 | /** |
||
86 | * @param string $varName The name of the variable to get template ident from. |
||
87 | * @throws InvalidArgumentException If the var name is not a string. |
||
88 | * @return string |
||
89 | */ |
||
90 | public function dynamicTemplate($varName) |
||
104 | |||
105 | /** |
||
106 | * @param string $varName The name of the variable to set this template unto. |
||
107 | * @param string|null $templateIdent The "dynamic template" to set or NULL to clear. |
||
108 | * @throws InvalidArgumentException If var name is not a string |
||
109 | * or if the template is not a string (and not null). |
||
110 | * @return void |
||
111 | */ |
||
112 | public function setDynamicTemplate($varName, $templateIdent) |
||
133 | |||
134 | /** |
||
135 | * @param string $varName The name of the variable to remove. |
||
136 | * @throws InvalidArgumentException If var name is not a string. |
||
137 | * @return void |
||
138 | */ |
||
139 | public function removeDynamicTemplate($varName) |
||
149 | |||
150 | /** |
||
151 | * @return void |
||
152 | */ |
||
153 | public function clearDynamicTemplates() |
||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | protected function basePath() |
||
165 | |||
166 | /** |
||
167 | * @param string $basePath The base path to set. |
||
168 | * @throws InvalidArgumentException If the base path parameter is not a string. |
||
169 | * @return LoaderInterface Chainable |
||
170 | */ |
||
171 | private function setBasePath($basePath) |
||
182 | |||
183 | /** |
||
184 | * @return string[] |
||
185 | */ |
||
186 | protected function paths() |
||
190 | |||
191 | /** |
||
192 | * @param string[] $paths The list of path to add. |
||
193 | * @return LoaderInterface Chainable |
||
194 | */ |
||
195 | private function setPaths(array $paths) |
||
205 | |||
206 | /** |
||
207 | * @param string $path The path to add to the load. |
||
208 | * @return LoaderInterface Chainable |
||
209 | */ |
||
210 | private function addPath($path) |
||
216 | |||
217 | /** |
||
218 | * @param string $path The path to resolve. |
||
219 | * @throws InvalidArgumentException If the path argument is not a string. |
||
220 | * @return string |
||
221 | */ |
||
222 | private function resolvePath($path) |
||
238 | |||
239 | /** |
||
240 | * Determine if the variable is a template literal. |
||
241 | * |
||
242 | * This method looks for any line-breaks in the given string, |
||
243 | * which a file path would not allow. |
||
244 | * |
||
245 | * @param string $ident The template being evaluated. |
||
246 | * @return boolean Returns TRUE if the given value is most likely the template contents |
||
247 | * as opposed to a template identifier (file path). |
||
248 | */ |
||
249 | protected function isTemplateString($ident) |
||
253 | |||
254 | /** |
||
255 | * Get the template file (full path + filename) to load from an ident. |
||
256 | * |
||
257 | * This method first generates the filename for an identifier and search for it in all of the loader's paths. |
||
258 | * |
||
259 | * @param string $ident The template identifier to load. |
||
260 | * @throws InvalidArgumentException If the template ident is not a string. |
||
261 | * @return string|null The full path + filename of the found template. Null if nothing was found. |
||
262 | */ |
||
263 | protected function findTemplateFile($ident) |
||
283 | |||
284 | /** |
||
285 | * @param string $ident The template identifier to convert to a filename. |
||
286 | * @return string |
||
287 | */ |
||
288 | abstract protected function filenameFromIdent($ident); |
||
289 | } |
||
290 |