catchAdmin/extend/catcher/event/LoadModuleRoutes.php

52 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;
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
$routes = $this->getRoutes();
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;
}
});
} 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;
}
});
}
2019-12-06 09:17:40 +08:00
}
2019-12-14 18:21:29 +08:00
2019-12-15 15:51:00 +08:00
/**
*
* @time 2019年12月15日
* @return array
*/
protected function getRoutes(): array
2019-12-14 18:21:29 +08:00
{
2019-12-15 15:51:00 +08:00
$routes = CatchAdmin::getRoutes();
2019-12-15 17:45:47 +08:00
array_push($routes, CatchAdmin::directory() . 'login' . DIRECTORY_SEPARATOR . 'route.php');
2019-12-15 15:51:00 +08:00
return $routes;
2019-12-14 18:21:29 +08:00
}
2019-12-06 09:17:40 +08:00
}