@@ 194-218 (lines=25) @@ | ||
191 | * @param string[] $hooks |
|
192 | * @return void |
|
193 | */ |
|
194 | public function loadRoutesFromPath($fromPath, $namespace = '', $hooks=[]) |
|
195 | { |
|
196 | $dir = @dir($fromPath) or abort("dir $fromPath not exist"); |
|
197 | ||
198 | $getEach = function () use ($dir) { |
|
199 | $name = $dir->read(); |
|
200 | if (!$name) { |
|
201 | return $name; |
|
202 | } |
|
203 | return $name; |
|
204 | }; |
|
205 | ||
206 | while (!!($entry = $getEach())) { |
|
207 | if ($entry == '.' || $entry == '..') { |
|
208 | continue; |
|
209 | } |
|
210 | $path = $fromPath . '/' . str_replace('\\', '/', $entry); |
|
211 | if (is_file($path) && substr_compare($entry, '.php', strlen($entry) - 4, 4, true) == 0) { |
|
212 | $class_name = $namespace . '\\' . substr($entry, 0, strlen($entry) - 4); |
|
213 | $this->loadRoutesFromClass($class_name, $hooks); |
|
214 | } else { |
|
215 | //\Log::debug($path.' ignored'); |
|
216 | } |
|
217 | } |
|
218 | } |
|
219 | ||
220 | /** |
|
221 | * Add route |
@@ 70-94 (lines=25) @@ | ||
67 | * @param string $namespace |
|
68 | * @throws \Exception |
|
69 | */ |
|
70 | public function loadCommandsFromPath($fromPath, $namespace = '') |
|
71 | { |
|
72 | $dir = @dir($fromPath) or abort("dir $fromPath not exist"); |
|
73 | ||
74 | $getEach = function () use ($dir) { |
|
75 | $name = $dir->read(); |
|
76 | if (!$name) { |
|
77 | return $name; |
|
78 | } |
|
79 | return $name; |
|
80 | }; |
|
81 | ||
82 | while (!!($entry = $getEach())) { |
|
83 | if ($entry == '.' || $entry == '..') { |
|
84 | continue; |
|
85 | } |
|
86 | $path = $fromPath . '/' . str_replace('\\', '/', $entry); |
|
87 | if (is_file($path) && substr_compare($entry, '.php', strlen($entry) - 4, 4, true) == 0) { |
|
88 | $class_name = $namespace . '\\' . substr($entry, 0, strlen($entry) - 4); |
|
89 | $this->loadCommandsFromClass($class_name); |
|
90 | } else { |
|
91 | //\Log::debug($path.' ignored'); |
|
92 | } |
|
93 | } |
|
94 | } |
|
95 | ||
96 | } |