mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
app路由检测改进 支持对 根目录 / 访问设置路由
This commit is contained in:
@@ -392,7 +392,6 @@ class App
|
|||||||
$_SERVER['PATH_INFO'] = '';
|
$_SERVER['PATH_INFO'] = '';
|
||||||
define('__INFO__', '');
|
define('__INFO__', '');
|
||||||
define('__EXT__', '');
|
define('__EXT__', '');
|
||||||
$result = ['type' => 'module', 'data' => [null, null, null], 'bind' => []];
|
|
||||||
} else {
|
} else {
|
||||||
$_SERVER['PATH_INFO'] = trim($_SERVER['PATH_INFO'], '/');
|
$_SERVER['PATH_INFO'] = trim($_SERVER['PATH_INFO'], '/');
|
||||||
define('__INFO__', $_SERVER['PATH_INFO']);
|
define('__INFO__', $_SERVER['PATH_INFO']);
|
||||||
@@ -404,29 +403,27 @@ class App
|
|||||||
}
|
}
|
||||||
// 去除正常的URL后缀
|
// 去除正常的URL后缀
|
||||||
$_SERVER['PATH_INFO'] = preg_replace($config['url_html_suffix'] ? '/\.(' . trim($config['url_html_suffix'], '.') . ')$/i' : '/\.' . __EXT__ . '$/i', '', __INFO__);
|
$_SERVER['PATH_INFO'] = preg_replace($config['url_html_suffix'] ? '/\.(' . trim($config['url_html_suffix'], '.') . ')$/i' : '/\.' . __EXT__ . '$/i', '', __INFO__);
|
||||||
$depr = $config['pathinfo_depr'];
|
}
|
||||||
// 还原劫持后真实pathinfo
|
|
||||||
$path_info = $_SERVER['PATH_INFO'];
|
|
||||||
|
|
||||||
// 路由检测
|
$depr = $config['pathinfo_depr'];
|
||||||
if (!empty($config['url_route_on'])) {
|
// 路由检测
|
||||||
// 开启路由 注册路由定义文件
|
if (!empty($config['url_route_on'])) {
|
||||||
Route::register(!empty($config['route']) ? $config['route'] : null);
|
// 开启路由 注册路由定义文件
|
||||||
// 路由检测(根据路由定义返回不同的URL调度)
|
Route::register(!empty($config['route']) ? $config['route'] : null);
|
||||||
$result = Route::check($path_info, $depr);
|
// 路由检测(根据路由定义返回不同的URL调度)
|
||||||
if (false === $result) {
|
$result = Route::check($_SERVER['PATH_INFO'], $depr);
|
||||||
// 路由无效
|
if (false === $result) {
|
||||||
if ($config['url_route_must']) {
|
// 路由无效
|
||||||
throw new Exception('route not define ');
|
if ($config['url_route_must']) {
|
||||||
} else {
|
throw new Exception('route not define ');
|
||||||
// 继续分析为模块/控制器/操作/参数...方式URL
|
} else {
|
||||||
$result = Route::parseUrl($path_info, $depr);
|
// 继续分析为模块/控制器/操作/参数...方式URL
|
||||||
}
|
$result = Route::parseUrl($_SERVER['PATH_INFO'], $depr);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// 分析URL地址 采用 模块/控制器/操作/参数...
|
|
||||||
$result = Route::parseUrl($path_info, $depr);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 分析URL地址 采用 模块/控制器/操作/参数...
|
||||||
|
$result = Route::parseUrl($_SERVER['PATH_INFO'], $depr);
|
||||||
}
|
}
|
||||||
// 注册调度机制
|
// 注册调度机制
|
||||||
self::dispatch($result);
|
self::dispatch($result);
|
||||||
|
|||||||
@@ -241,15 +241,16 @@ class Route
|
|||||||
// 检测域名部署
|
// 检测域名部署
|
||||||
self::checkDomain();
|
self::checkDomain();
|
||||||
|
|
||||||
|
if (isset(self::$bind['module'])) {
|
||||||
|
// 如果有模块/控制器绑定
|
||||||
|
$url = implode('/', self::$bind['module']) . '/' . $url;
|
||||||
|
}
|
||||||
|
|
||||||
// 优先检测是否存在PATH_INFO
|
// 优先检测是否存在PATH_INFO
|
||||||
if (empty($url)) {
|
if (empty($url)) {
|
||||||
$url = '/';
|
$url = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset(self::$bind['module'])) {
|
|
||||||
$url = implode('/', self::$bind['module']) . '/' . $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分隔符替换 确保路由定义使用统一的分隔符
|
// 分隔符替换 确保路由定义使用统一的分隔符
|
||||||
if ('/' != $depr) {
|
if ('/' != $depr) {
|
||||||
$url = str_replace($depr, '/', $url);
|
$url = str_replace($depr, '/', $url);
|
||||||
|
|||||||
Reference in New Issue
Block a user