fix: 初始化异常
This commit is contained in:
@@ -582,17 +582,22 @@ if (!function_exists('saenv')) {
|
||||
{
|
||||
$redis = 'config_' . $name;
|
||||
$config = Cache::get($redis);
|
||||
$configList = Cache::get('config_list') ?? [];
|
||||
if (empty($config)) {
|
||||
$config = $group ? Config::all($name, true) : Config::where('name', $name)->value('value');
|
||||
if (!empty($config)) {
|
||||
$configList[$name] = $redis;
|
||||
Cache::set($redis, $config);
|
||||
Cache::set('config_list', $configList);
|
||||
}
|
||||
}
|
||||
|
||||
return $config ?: false;
|
||||
try {
|
||||
|
||||
$configList = Cache::get('config_list') ?? [];
|
||||
if (empty($config)) {
|
||||
$config = $group ? Config::all($name, true) : Config::where('name', $name)->value('value');
|
||||
if (!empty($config)) {
|
||||
$configList[$name] = $redis;
|
||||
Cache::set($redis, $config);
|
||||
Cache::set('config_list', $configList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,6 +666,21 @@ if (!function_exists('system_reload')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_routes')) {
|
||||
/**
|
||||
* 获取系统配置信息
|
||||
*/
|
||||
function get_routes(): array
|
||||
{
|
||||
$routeList = [];
|
||||
$routes = \Webman\Route::getRoutes();
|
||||
foreach ($routes as $tmp_route) {
|
||||
$routeList[] = $tmp_route->getPath();
|
||||
}
|
||||
return $routeList;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('parse_array_ini')) {
|
||||
/**
|
||||
* 解析数组到ini文件
|
||||
@@ -1299,7 +1319,7 @@ if (!function_exists('plugin_refresh_hooks')) {
|
||||
$parse = explode('/', $route);
|
||||
$action = end($parse);
|
||||
array_pop($parse);
|
||||
$path = implode('/', $parse);
|
||||
$path = implode('\\', $parse);
|
||||
$controller = 'app\\index\\controller\\' . $path;
|
||||
if (class_exists($controller) && method_exists($controller, $action)) {
|
||||
$controller = preg_replace('#//#', '/', $controller);
|
||||
|
||||
@@ -28,13 +28,6 @@ Route::any('/manage', function () {
|
||||
|
||||
Route::any('/captcha', [app\BaseController::class, 'captcha']);
|
||||
|
||||
$ignoreList = [];
|
||||
$routes = Route::getRoutes();
|
||||
// 获取已存在路由
|
||||
foreach ($routes as $tmp_route) {
|
||||
$ignoreList[] = $tmp_route->getPath();
|
||||
}
|
||||
|
||||
// 遍历默认应用文件夹
|
||||
$default_app = config('app.default_app', 'index');
|
||||
$files = new \RecursiveIteratorIterator(
|
||||
@@ -67,33 +60,24 @@ foreach ($files as $file) {
|
||||
$className = $refClass->name;
|
||||
$methods = $refClass->getMethods(\ReflectionMethod::IS_PUBLIC);
|
||||
|
||||
$route = function ($url, $action) use ($ignoreList) {
|
||||
if (in_array($url, $ignoreList) || empty($url)) {
|
||||
return;
|
||||
$route = function ($url, $action) {
|
||||
if (!in_array($url, get_routes()) && !empty($url)) {
|
||||
$url = strtolower($url);
|
||||
Route::any($url, $action);
|
||||
}
|
||||
|
||||
$url = strtolower($url);
|
||||
Route::any($url, $action);
|
||||
};
|
||||
|
||||
foreach ($methods as $item) {
|
||||
|
||||
$action = $item->name;
|
||||
|
||||
$magic = [
|
||||
'__construct', '__destruct', '__call', '__callStatic', '__get', '__set','__isset', '__unset', '__sleep', '__wakeup', '__toString',
|
||||
'__invoke', '__set_state', '__clone', '__autoload', '__debugInfo', 'initialize',
|
||||
];
|
||||
|
||||
// 过滤魔术方法
|
||||
if (in_array($action,$magic)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 执行路由代码
|
||||
if ($action === 'index') {
|
||||
if (strtolower(substr($urlPath, -6)) === '/index') {
|
||||
// 默认路由
|
||||
if (strtolower(substr($urlPath, -6)) === '/index' && $urlPath === '/Index') {
|
||||
$route('/', [$className, $action]);
|
||||
$route(substr($urlPath, 0, -6), [$className, $action]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user