| @@ 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 |
|
| @@ 53-77 (lines=25) @@ | ||
| 50 | * @param string $namespace |
|
| 51 | * @throws \Exception |
|
| 52 | */ |
|
| 53 | public function loadRoutesFromPath($fromPath, $namespace = '') |
|
| 54 | { |
|
| 55 | $dir = @dir($fromPath) or abort("dir $fromPath not exist"); |
|
| 56 | ||
| 57 | $getEach = function () use ($dir) { |
|
| 58 | $name = $dir->read(); |
|
| 59 | if (!$name) { |
|
| 60 | return $name; |
|
| 61 | } |
|
| 62 | return $name; |
|
| 63 | }; |
|
| 64 | ||
| 65 | while (!!($entry = $getEach())) { |
|
| 66 | if ($entry == '.' || $entry == '..') { |
|
| 67 | continue; |
|
| 68 | } |
|
| 69 | $path = $fromPath . '/' . str_replace('\\', '/', $entry); |
|
| 70 | if (is_file($path) && substr_compare($entry, '.php', strlen($entry) - 4, 4, true) == 0) { |
|
| 71 | $class_name = $namespace . '\\' . substr($entry, 0, strlen($entry) - 4); |
|
| 72 | $this->loadCommandsFromClass($class_name); |
|
| 73 | } else { |
|
| 74 | //\Log::debug($path.' ignored'); |
|
| 75 | } |
|
| 76 | } |
|
| 77 | } |
|
| 78 | ||
| 79 | } |
|