修改路由加载

This commit is contained in:
wuyanwen 2019-12-15 15:51:00 +08:00
parent 0d05e4ecbd
commit aea9eb6a17
2 changed files with 32 additions and 22 deletions

View File

@ -244,17 +244,15 @@ class CatchAdmin
/**
*
* @time 2019年11月30日
* @return string
* @return mixed
*/
public static function getRoutes(): string
public static function getRoutes()
{
if (file_exists(self::getCacheRoutesFile())) {
return self::getCacheRoutesFile();
}
self::cacheRoutes();
return self::getCacheRoutesFile();
return self::getModuleRoutes();
}
/**
@ -271,6 +269,24 @@ class CatchAdmin
return self::getModuleViews();
}
/**
*
* @time 2019年12月15日
* @return array
*/
public static function getModuleRoutes(): array
{
$routeFiles = [];
foreach (self::getModulesDirectory() as $module) {
$moduleInfo = self::getModuleInfo($module);
if (!in_array($moduleInfo['alias'], ['login']) && file_exists($module . 'route.php')) {
$routeFiles[] = $module . 'route.php';
}
}
return $routeFiles;
}
/**
*
* @time 2019年11月30日
@ -278,17 +294,9 @@ class CatchAdmin
*/
public static function cacheRoutes()
{
$routeFiles = [];
foreach (self::getModulesDirectory() as $module) {
$moduleInfo = self::getModuleInfo($module);
if (!in_array($moduleInfo['alias'], ['login'])) {
if (file_exists($module . 'route.php')) {
$routeFiles[] = $module . 'route.php';
}
}
}
$routes = '';
foreach ($routeFiles as $route) {
foreach (self::getModuleRoutes() as $route) {
$routes .= trim(str_replace('<?php', '', file_get_contents($route))) . PHP_EOL;
}

View File

@ -25,13 +25,15 @@ class LoadModuleRoutes
});
}
protected function getRoutes()
/**
*
* @time 2019年12月15日
* @return array
*/
protected function getRoutes(): array
{
return [
CatchAdmin::directory() . 'login' . DIRECTORY_SEPARATOR . 'route.php',
CatchAdmin::getRoutes(),
];
$routes = CatchAdmin::getRoutes();
$routes[] = CatchAdmin::directory() . 'login' . DIRECTORY_SEPARATOR . 'route.php';
return $routes;
}
}