catchAdmin/extend/catcher/event/LoadModuleRoutes.php

38 lines
871 B
PHP
Raw Permalink Normal View History

2019-12-06 09:17:40 +08:00
<?php
declare (strict_types = 1);
namespace catcher\event;
2020-06-24 09:11:08 +08:00
use think\App;
2019-12-06 09:17:40 +08:00
use think\Route;
class LoadModuleRoutes
{
/**
* 处理
*
* @time 2019年11月29日
* @return void
*/
public function handle(): void
{
$router = app(Route::class);
2019-12-15 17:26:40 +08:00
$domain = config('catch.domain');
2020-06-24 09:11:08 +08:00
$paths = app(App::class)->make('routePath')->get();
// $routeMiddleware = config('catch.route_middleware');
2019-12-15 17:26:40 +08:00
if ($domain) {
2020-06-24 09:11:08 +08:00
$router->domain($domain, function () use ($router, $paths) {
foreach ($paths as $path) {
include $path;
2019-12-15 17:26:40 +08:00
}
2020-06-24 09:11:08 +08:00
});
2019-12-15 17:26:40 +08:00
} else {
2020-06-24 09:11:08 +08:00
$router->group(function () use ($router, $paths) {
foreach ($paths as $path) {
include $path;
2019-12-15 17:26:40 +08:00
}
2020-06-24 09:11:08 +08:00
});
2019-12-15 17:26:40 +08:00
}
2019-12-06 09:17:40 +08:00
}
}