catchAdmin/extend/catcher/event/LoadModuleRoutes.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2019-12-06 09:17:40 +08:00
<?php
declare (strict_types = 1);
namespace catcher\event;
2020-02-18 14:44:16 +08:00
use catchAdmin\permissions\PermissionsMiddleware;
2019-12-22 09:37:52 +08:00
use catchAdmin\user\AuthTokenMiddleware;
2019-12-06 09:17:40 +08:00
use catcher\CatchAdmin;
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');
2019-12-15 17:45:47 +08:00
2020-01-07 18:04:05 +08:00
$routes = CatchAdmin::getRoutes();
2019-12-15 17:45:47 +08:00
2020-02-18 14:52:32 +08:00
$routeMiddleware = config('catch.route_middleware');
2019-12-15 17:26:40 +08:00
if ($domain) {
2019-12-15 17:45:47 +08:00
$router->domain($domain, function () use ($router, $routes) {
foreach ($routes as $route) {
2019-12-15 17:26:40 +08:00
include $route;
}
2020-02-18 14:52:32 +08:00
})->middleware($routeMiddleware);
2019-12-15 17:26:40 +08:00
} else {
2019-12-15 17:45:47 +08:00
$router->group(function () use ($router, $routes) {
foreach ($routes as $route) {
2019-12-15 17:26:40 +08:00
include $route;
}
2020-02-18 14:52:32 +08:00
})->middleware($routeMiddleware);
2019-12-15 17:26:40 +08:00
}
2019-12-22 09:37:52 +08:00
// 单独加载登录
include CatchAdmin::moduleDirectory('login') . 'route.php';
2019-12-06 09:17:40 +08:00
}
}