|
10 | 10 | // +---------------------------------------------------------------------- |
11 | 11 | namespace think\console\command; |
12 | 12 |
|
13 | | -use DirectoryIterator; |
14 | 13 | use think\console\Command; |
15 | 14 | use think\console\Input; |
16 | 15 | use think\console\input\Argument; |
17 | 16 | use think\console\input\Option; |
18 | 17 | use think\console\Output; |
19 | 18 | use think\console\Table; |
20 | 19 | use think\event\RouteLoaded; |
21 | | -use think\facade\Route; |
22 | 20 |
|
23 | 21 | class RouteList extends Command |
24 | 22 | { |
@@ -50,42 +48,21 @@ protected function execute(Input $input, Output $output) |
50 | 48 | } |
51 | 49 |
|
52 | 50 | $content = $this->getRouteList(); |
53 | | - file_put_contents($filename, 'Route List' . PHP_EOL . $content); |
| 51 | + file_put_contents($filename, 'Route List:' . PHP_EOL . $content); |
54 | 52 | } |
55 | 53 |
|
56 | | - protected function scanRoute($path, $root) |
57 | | - { |
58 | | - $iterator = new DirectoryIterator($path); |
59 | | - foreach ($iterator as $fileinfo) { |
60 | | - if ($fileinfo->isDot()) { |
61 | | - continue; |
62 | | - } |
63 | | - |
64 | | - if ($fileinfo->getType() == 'file' && $fileinfo->getExtension() == 'php') { |
65 | | - $groupName = str_replace('\\', '/', substr_replace($fileinfo->getPath(), '', 0, strlen($root))); |
66 | | - if ($groupName) { |
67 | | - Route::group($groupName, function() use ($fileinfo) { |
68 | | - include $fileinfo->getRealPath(); |
69 | | - }); |
70 | | - } else { |
71 | | - include $fileinfo->getRealPath(); |
72 | | - } |
73 | | - } |
74 | | - |
75 | | - if ($fileinfo->isDir()) { |
76 | | - $this->scanRoute($fileinfo->getPathname(), $root); |
77 | | - } |
78 | | - } |
79 | | - } |
80 | | - |
81 | | - protected function getRouteList(?string $dir = null): string |
| 54 | + protected function getRouteList(): string |
82 | 55 | { |
83 | 56 | $this->app->route->clear(); |
84 | 57 | $this->app->route->lazy(false); |
| 58 | + $path = $this->app->getRootPath() . 'route' . DIRECTORY_SEPARATOR; |
| 59 | + $files = is_dir($path) ? scandir($path) : []; |
85 | 60 |
|
86 | | - $path = $this->app->getRootPath() . 'route' . DIRECTORY_SEPARATOR; |
87 | | - |
88 | | - $this->scanRoute($path, $path); |
| 61 | + foreach ($files as $file) { |
| 62 | + if (str_contains($file, '.php')) { |
| 63 | + include $path . $file; |
| 64 | + } |
| 65 | + } |
89 | 66 |
|
90 | 67 | //触发路由载入完成事件 |
91 | 68 | $this->app->event->trigger(RouteLoaded::class); |
|
0 commit comments