Skip to content

Commit 7260123

Browse files
committed
调整 think route:list指令
1 parent db3aeb0 commit 7260123

1 file changed

Lines changed: 9 additions & 32 deletions

File tree

src/think/console/command/RouteList.php

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
// +----------------------------------------------------------------------
1111
namespace think\console\command;
1212

13-
use DirectoryIterator;
1413
use think\console\Command;
1514
use think\console\Input;
1615
use think\console\input\Argument;
1716
use think\console\input\Option;
1817
use think\console\Output;
1918
use think\console\Table;
2019
use think\event\RouteLoaded;
21-
use think\facade\Route;
2220

2321
class RouteList extends Command
2422
{
@@ -50,42 +48,21 @@ protected function execute(Input $input, Output $output)
5048
}
5149

5250
$content = $this->getRouteList();
53-
file_put_contents($filename, 'Route List' . PHP_EOL . $content);
51+
file_put_contents($filename, 'Route List:' . PHP_EOL . $content);
5452
}
5553

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
8255
{
8356
$this->app->route->clear();
8457
$this->app->route->lazy(false);
58+
$path = $this->app->getRootPath() . 'route' . DIRECTORY_SEPARATOR;
59+
$files = is_dir($path) ? scandir($path) : [];
8560

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+
}
8966

9067
//触发路由载入完成事件
9168
$this->app->event->trigger(RouteLoaded::class);

0 commit comments

Comments
 (0)