1 | <?php |
||
18 | class TemplateRegistry |
||
19 | { |
||
20 | /** |
||
21 | * |
||
22 | * The map of explicit template names and locations. |
||
23 | * |
||
24 | * @var array |
||
25 | * |
||
26 | */ |
||
27 | protected $map = array(); |
||
28 | |||
29 | /** |
||
30 | * |
||
31 | * The paths to search for implicit template names. |
||
32 | * |
||
33 | * @var array |
||
34 | * |
||
35 | */ |
||
36 | protected $paths = array(); |
||
37 | |||
38 | /** |
||
39 | * |
||
40 | * The namespaced paths to search for implicit template names. |
||
41 | * |
||
42 | * @var array |
||
43 | * |
||
44 | */ |
||
45 | protected $namespaces = array(); |
||
46 | |||
47 | /** |
||
48 | * |
||
49 | * Templates found in the search paths. |
||
50 | * |
||
51 | * @var array |
||
52 | * |
||
53 | */ |
||
54 | protected $found = array(); |
||
55 | |||
56 | /** |
||
57 | * |
||
58 | * File extension to use when searching the path list for templates. |
||
59 | * |
||
60 | * @var string |
||
61 | * |
||
62 | */ |
||
63 | protected $templateFileExtension = '.php'; |
||
64 | |||
65 | /** |
||
66 | * |
||
67 | * Constructor. |
||
68 | * |
||
69 | * @param array $map A map of explicit template names and locations. |
||
70 | * |
||
71 | * @param array $paths A map of filesystem paths to search for templates. |
||
72 | * |
||
73 | * @param array $namespaces A map of filesystem paths to search for namespaced templates. |
||
74 | * |
||
75 | */ |
||
76 | 19 | public function __construct( |
|
87 | |||
88 | /** |
||
89 | * |
||
90 | * Registers a template. |
||
91 | * |
||
92 | * If the template is a string, it is treated as a path to a PHP include |
||
93 | * file, and gets wrapped inside a closure that includes that file. |
||
94 | * Otherwise the template is treated as a callable. |
||
95 | * |
||
96 | * @param string $name Register the template under this name. |
||
97 | * |
||
98 | * @param string|callable $spec A string path to a PHP include file, or a |
||
99 | * callable. |
||
100 | * |
||
101 | * @return null |
||
102 | * |
||
103 | */ |
||
104 | 11 | public function set($name, $spec) |
|
111 | |||
112 | /** |
||
113 | * |
||
114 | * Is a named template registered? |
||
115 | * |
||
116 | * @param string $name The template name. |
||
117 | * |
||
118 | * @return bool |
||
119 | * |
||
120 | */ |
||
121 | 1 | public function has($name) |
|
125 | |||
126 | /** |
||
127 | * |
||
128 | * Is a namespace registered? |
||
129 | * |
||
130 | * @param string $name The namespace. |
||
|
|||
131 | * |
||
132 | * @return bool |
||
133 | * |
||
134 | */ |
||
135 | 2 | public function hasNamespace($namespace) |
|
139 | |||
140 | /** |
||
141 | * |
||
142 | * Gets a template from the registry. |
||
143 | * |
||
144 | * @param string $name The template name. |
||
145 | * |
||
146 | * @return \Closure |
||
147 | * |
||
148 | */ |
||
149 | 11 | public function get($name) |
|
161 | |||
162 | /** |
||
163 | * |
||
164 | * Gets a copy of the current search paths. |
||
165 | * |
||
166 | * @return array |
||
167 | * |
||
168 | */ |
||
169 | 3 | public function getPaths() |
|
173 | |||
174 | /** |
||
175 | * |
||
176 | * Adds one path to the top of the search paths. |
||
177 | * |
||
178 | * $registry->prependPath('/path/1'); |
||
179 | * $registry->prependPath('/path/2'); |
||
180 | * $registry->prependPath('/path/3'); |
||
181 | * // $this->getPaths() reveals that the directory search |
||
182 | * // order will be '/path/3/', '/path/2/', '/path/1/'. |
||
183 | * |
||
184 | * @param string $path The directories to add to the paths. |
||
185 | * @param string|null $namespace The directory namespace |
||
186 | * |
||
187 | * @return null |
||
188 | * |
||
189 | */ |
||
190 | 2 | public function prependPath($path, $namespace = null) |
|
204 | |||
205 | /** |
||
206 | * |
||
207 | * Adds one path to the end of the search paths. |
||
208 | * |
||
209 | * $registry->appendPath('/path/1'); |
||
210 | * $registry->appendPath('/path/2'); |
||
211 | * $registry->appendPath('/path/3'); |
||
212 | * // $registry->getPaths() reveals that the directory search |
||
213 | * // order will be '/path/1/', '/path/2/', '/path/3/'. |
||
214 | * |
||
215 | * @param array|string $path The directories to add to the paths. |
||
216 | * @param string|null $namespace The directory namespace |
||
217 | * |
||
218 | * @return null |
||
219 | * |
||
220 | */ |
||
221 | 3 | public function appendPath($path, $namespace = null) |
|
236 | |||
237 | /** |
||
238 | * |
||
239 | * Sets the paths directly. |
||
240 | * |
||
241 | * $registry->setPaths([ |
||
242 | * '/path/1', |
||
243 | * '/path/2', |
||
244 | * '/path/3', |
||
245 | * ]); |
||
246 | * // $registry->getPaths() reveals that the search order will |
||
247 | * // be '/path/1', '/path/2', '/path/3'. |
||
248 | * |
||
249 | * @param array $paths The paths to set. |
||
250 | * |
||
251 | * @return null |
||
252 | * |
||
253 | */ |
||
254 | 19 | public function setPaths(array $paths) |
|
259 | |||
260 | /** |
||
261 | * Set namespaces directly |
||
262 | * |
||
263 | * @param array $namespaces array of namesspaces |
||
264 | * |
||
265 | * @return void |
||
266 | * |
||
267 | * @access public |
||
268 | */ |
||
269 | 19 | public function setNamespaces(array $namespaces) |
|
274 | |||
275 | /** |
||
276 | * |
||
277 | * Sets the extension to be used when searching for templates via find(). |
||
278 | * |
||
279 | * @param string $templateFileExtension |
||
280 | * |
||
281 | * @return null |
||
282 | * |
||
283 | */ |
||
284 | 1 | public function setTemplateFileExtension($templateFileExtension) |
|
288 | |||
289 | /** |
||
290 | * |
||
291 | * Finds a template in the search paths. |
||
292 | * |
||
293 | * @param string $name The template name. |
||
294 | * |
||
295 | * @return bool True if found, false if not. |
||
296 | * |
||
297 | */ |
||
298 | 5 | protected function find($name) |
|
318 | |||
319 | /** |
||
320 | * Parse namespaced template name |
||
321 | * |
||
322 | * @param string $name namespaced template name |
||
323 | * |
||
324 | * @return array |
||
325 | * @throws InvalidArgumentException if invalid template name |
||
326 | * |
||
327 | * @access protected |
||
328 | */ |
||
329 | 5 | protected function parseName($name) |
|
347 | |||
348 | /** |
||
349 | * Is template name namespaced? |
||
350 | * |
||
351 | * @param string $name name to check |
||
352 | * |
||
353 | * @return bool |
||
354 | * |
||
355 | * @access protected |
||
356 | */ |
||
357 | 5 | protected function isNamespaced($name) |
|
362 | |||
363 | /** |
||
364 | * Fine a namespaced template |
||
365 | * |
||
366 | * @param string $name namespaced template name |
||
367 | * |
||
368 | * @return bool |
||
369 | * |
||
370 | * @access protected |
||
371 | */ |
||
372 | 2 | protected function findNamespaced($name) |
|
394 | |||
395 | /** |
||
396 | * |
||
397 | * Checks to see if a file is readable. |
||
398 | * |
||
399 | * @param string $file The file to find. |
||
400 | * |
||
401 | * @return bool |
||
402 | * |
||
403 | */ |
||
404 | 2 | protected function isReadable($file) |
|
408 | |||
409 | /** |
||
410 | * |
||
411 | * Wraps a template file name in a Closure. |
||
412 | * |
||
413 | * @param string $__FILE__ The file name. |
||
414 | * |
||
415 | * @return \Closure |
||
416 | * |
||
417 | */ |
||
418 | protected function enclose($__FILE__) |
||
425 | } |
||
426 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.