1 | <?php |
||
13 | class Scanner |
||
14 | { |
||
15 | /** |
||
16 | * Return all sections (app & plugins) with an Template directory. |
||
17 | * |
||
18 | * @return array |
||
19 | */ |
||
20 | // @codingStandardsIgnoreStart |
||
21 | 5 | public static function all() |
|
22 | { |
||
23 | // @codingStandardsIgnoreEnd |
||
24 | 5 | $sections = []; |
|
25 | |||
26 | 5 | foreach (App::path('Template') as $path) { |
|
27 | 3 | if (is_dir($path)) { |
|
28 | 3 | $sections['APP'] = isset($sections['APP']) ? $sections['APP'] : []; |
|
29 | 3 | $sections['APP'] = array_merge($sections['APP'], static::iteratePath($path)); |
|
30 | } |
||
31 | } |
||
32 | |||
33 | 5 | foreach (static::pluginsWithTemplates() as $plugin) { |
|
34 | 5 | foreach (App::path('Template', $plugin) as $path) { |
|
35 | 5 | if (is_dir($path)) { |
|
36 | 5 | $sections[$plugin] = isset($sections[$plugin]) ? $sections[$plugin] : []; |
|
37 | 5 | $sections[$plugin] = array_merge($sections[$plugin], static::iteratePath($path)); |
|
38 | } |
||
39 | } |
||
40 | } |
||
41 | |||
42 | 5 | return static::clearEmptySections($sections); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Check sections a remove the ones without anything in them. |
||
47 | * |
||
48 | * @param array $sections Sections to check. |
||
49 | * |
||
50 | * @return array |
||
51 | */ |
||
52 | 5 | protected static function clearEmptySections(array $sections) |
|
53 | { |
||
54 | array_walk($sections, function ($templates, $index) use (&$sections) { |
||
55 | 5 | if (count($templates) == 0) { |
|
56 | 5 | unset($sections[$index]); |
|
57 | } |
||
58 | 5 | }); |
|
59 | |||
60 | 5 | return $sections; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Finds all plugins with a Template directory. |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | 5 | protected static function pluginsWithTemplates() |
|
69 | { |
||
70 | 5 | $plugins = Plugin::loaded(); |
|
71 | |||
72 | array_walk($plugins, function ($plugin, $index) use (&$plugins) { |
||
|
|||
73 | 5 | $paths = App::path('Template', $plugin); |
|
74 | |||
75 | array_walk($paths, function ($path, $index) use (&$paths) { |
||
76 | 5 | if (!is_dir($path)) { |
|
77 | 5 | unset($paths[$index]); |
|
78 | } |
||
79 | 5 | }); |
|
80 | 5 | }); |
|
81 | |||
82 | 5 | return $plugins; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Return all templates for a given plugin. |
||
87 | * |
||
88 | * @param string $plugin The plugin to find all templates for. |
||
89 | * |
||
90 | * @return mixed |
||
91 | */ |
||
92 | 4 | public static function plugin($plugin) |
|
93 | { |
||
94 | 4 | $templates = []; |
|
95 | |||
96 | 4 | foreach (App::path('Template', $plugin) as $path) { |
|
97 | 3 | $templates = array_merge($templates, static::iteratePath($path)); |
|
98 | } |
||
99 | |||
100 | 3 | return $templates; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Iterage over the given path and return all matching .tpl files in it. |
||
105 | * |
||
106 | * @param string $path Path to iterate over. |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | 8 | protected static function iteratePath($path) |
|
114 | |||
115 | /** |
||
116 | * Setup iterator for given path. |
||
117 | * |
||
118 | * @param string $path Path to setup iterator for. |
||
119 | * |
||
120 | * @return \Iterator |
||
121 | */ |
||
122 | 8 | protected static function setupIterator($path) |
|
135 | |||
136 | /** |
||
137 | * Walk over the iterator and compile all templates. |
||
138 | * |
||
139 | * @param \Iterator $iterator Iterator to walk. |
||
140 | * |
||
141 | * @return array |
||
142 | */ |
||
143 | // @codingStandardsIgnoreStart |
||
144 | 8 | protected static function walkIterator(\Iterator $iterator) |
|
165 | // @codingStandardsIgnoreEnd |
||
166 | } |
||
167 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.