These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace League\Plates\Extension\Folders; |
||
4 | |||
5 | use League\Plates; |
||
6 | |||
7 | final class FoldersExtension implements Plates\Extension |
||
8 | { |
||
9 | 16 | public function register(Plates\Engine $plates) { |
|
10 | 16 | $c = $plates->getContainer(); |
|
11 | 16 | $c->add('folders.folders', []); |
|
12 | 16 | $c->wrapStack('path.resolvePath', function($stack, $c) { |
|
13 | $config = $c; |
||
14 | 16 | return array_merge($stack, [ |
|
15 | 16 | 'folders' => foldersResolvePath( |
|
16 | 16 | $c->get('folders.folders'), |
|
17 | 16 | $c->get('config')['folder_separator'], |
|
18 | 16 | $c->get('fileExists') |
|
19 | 16 | ) |
|
20 | 16 | ]); |
|
21 | 16 | }); |
|
22 | $c->wrapComposed('path.normalizeName', function($composed, $c) { |
||
23 | return array_merge($composed, [ |
||
24 | 16 | 'folders.stripFolders' => stripFoldersNormalizeName($c->get('folders.folders')) |
|
25 | 16 | ]); |
|
26 | 16 | }); |
|
27 | 16 | ||
28 | $plates->defineConfig([ |
||
0 ignored issues
–
show
|
|||
29 | 16 | 'folder_separator' => '::', |
|
30 | 16 | ]); |
|
31 | 16 | $plates->addMethods([ |
|
32 | 4 | 'addFolder' => function($plates, $folder, $prefixes, $fallback = false) { |
|
33 | 4 | $prefixes = is_string($prefixes) ? [$prefixes] : $prefixes; |
|
34 | if ($fallback) { |
||
35 | $prefixes[] = ''; |
||
36 | 4 | } |
|
37 | $plates->getContainer()->merge('folders.folders', [ |
||
38 | 4 | $folder => [ |
|
39 | 4 | 'folder' => $folder, |
|
40 | 'prefixes' => $prefixes, |
||
41 | ] |
||
42 | 16 | ]); |
|
43 | }, |
||
44 | 16 | ]); |
|
45 | } |
||
46 | } |
||
47 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: