mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
完善路由类的parseUrl方法对设置不同的pathinfo_depr的支持
This commit is contained in:
@@ -225,16 +225,13 @@ class App
|
|||||||
// CLI模式下 index.php module/controller/action/params/...
|
// CLI模式下 index.php module/controller/action/params/...
|
||||||
$_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';
|
$_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';
|
||||||
}
|
}
|
||||||
// [模块,控制器,操作]
|
|
||||||
$result = [null, null, null];
|
|
||||||
|
|
||||||
// 检测域名部署
|
// 检测域名部署
|
||||||
if (!IS_CLI && !empty($config['domain_deploy'])) {
|
if (!IS_CLI && !empty($config['domain_deploy'])) {
|
||||||
if ($match = Route::checkDomain($config['domain_rules'])) {
|
if ($match = Route::checkDomain($config['domain_rules'])) {
|
||||||
$result = $match;
|
(!defined('BIND_MODULE') && !empty($match[0])) && define('BIND_MODULE', $match[0]);
|
||||||
(!defined('BIND_MODULE') && !empty($result[0])) && define('BIND_MODULE', $result[0]);
|
(!defined('BIND_CONTROLLER') && !empty($match[1])) && define('BIND_CONTROLLER', $match[1]);
|
||||||
(!defined('BIND_CONTROLLER') && !empty($result[1])) && define('BIND_CONTROLLER', $result[1]);
|
(!defined('BIND_ACTION') && !empty($match[2])) && define('BIND_ACTION', $match[2]);
|
||||||
(!defined('BIND_ACTION') && !empty($result[2])) && define('BIND_ACTION', $result[2]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,6 +253,9 @@ class App
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [模块,控制器,操作]
|
||||||
|
$result = [null, null, null];
|
||||||
|
|
||||||
if (empty($_SERVER['PATH_INFO'])) {
|
if (empty($_SERVER['PATH_INFO'])) {
|
||||||
$_SERVER['PATH_INFO'] = '';
|
$_SERVER['PATH_INFO'] = '';
|
||||||
define('__INFO__', '');
|
define('__INFO__', '');
|
||||||
@@ -265,28 +265,35 @@ class App
|
|||||||
define('__INFO__', $_SERVER['PATH_INFO']);
|
define('__INFO__', $_SERVER['PATH_INFO']);
|
||||||
// URL后缀
|
// URL后缀
|
||||||
define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION)));
|
define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION)));
|
||||||
$_SERVER['PATH_INFO'] = __INFO__;
|
|
||||||
if (__INFO__) {
|
if (__INFO__) {
|
||||||
if ($config['url_deny_suffix'] && preg_match('/\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) {
|
if ($config['url_deny_suffix'] && preg_match('/\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) {
|
||||||
throw new Exception('URL_SUFFIX_DENY');
|
throw new Exception('URL_SUFFIX_DENY');
|
||||||
}
|
}
|
||||||
|
$depr = $config['pathinfo_depr'];
|
||||||
// 还原劫持后真实pathinfo
|
// 还原劫持后真实pathinfo
|
||||||
$path_info = (defined('BIND_MODULE')?BIND_MODULE.'/':'') . (defined('BIND_CONTROLLER')?BIND_CONTROLLER.'/':'') . (defined('BIND_ACTION')?BIND_ACTION.'/':'') . __INFO__;
|
$path_info =
|
||||||
|
(defined('BIND_MODULE') ? BIND_MODULE . $depr : '') .
|
||||||
|
(defined('BIND_CONTROLLER') ? BIND_CONTROLLER . $depr : '') .
|
||||||
|
(defined('BIND_ACTION') ? BIND_ACTION . $depr : '') .
|
||||||
|
__INFO__;
|
||||||
|
|
||||||
// 路由检测
|
// 路由检测
|
||||||
if (!empty($config['url_route_on'])) {
|
if (!empty($config['url_route_on'])) {
|
||||||
// 开启路由 则检测路由配置
|
// 开启路由 则检测路由配置
|
||||||
Route::register($config['route']);
|
Route::register($config['route']);
|
||||||
$result = Route::check($path_info, $config['pathinfo_depr']);
|
$result = Route::check($path_info, $depr);
|
||||||
if (false === $result) {
|
if (false === $result) {
|
||||||
// 路由无效
|
// 路由无效
|
||||||
if ($config['url_route_must']) {
|
if ($config['url_route_must']) {
|
||||||
throw new Exception('route not define ');
|
throw new Exception('route not define ');
|
||||||
} else {
|
} else {
|
||||||
$result = Route::parseUrl($path_info);
|
// 继续分析URL
|
||||||
|
$result = Route::parseUrl($path_info, $depr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$result = Route::parseUrl($path_info);
|
// 分析URL地址
|
||||||
|
$result = Route::parseUrl($path_info, $depr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 去除URL后缀
|
// 去除URL后缀
|
||||||
|
|||||||
@@ -217,13 +217,12 @@ class Route
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检测URL路由
|
// 检测URL路由
|
||||||
public static function check($url, $depr = '/', &$result = [])
|
public static function check($url, $depr = '/')
|
||||||
{
|
{
|
||||||
// 优先检测是否存在PATH_INFO
|
// 优先检测是否存在PATH_INFO
|
||||||
if (empty($url)) {
|
if (empty($url)) {
|
||||||
$url = '/';
|
$url = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分隔符替换 确保路由定义使用统一的分隔符
|
// 分隔符替换 确保路由定义使用统一的分隔符
|
||||||
if ('/' != $depr) {
|
if ('/' != $depr) {
|
||||||
$url = str_replace($depr, '/', $url);
|
$url = str_replace($depr, '/', $url);
|
||||||
@@ -419,8 +418,12 @@ class Route
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 解析模块的URL地址 [模块/控制器/操作?]参数1=值1&参数2=值2...
|
// 解析模块的URL地址 [模块/控制器/操作?]参数1=值1&参数2=值2...
|
||||||
public static function parseUrl($url)
|
public static function parseUrl($url, $depr = '/')
|
||||||
{
|
{
|
||||||
|
// 分隔符替换 确保路由定义使用统一的分隔符
|
||||||
|
if ('/' != $depr) {
|
||||||
|
$url = str_replace($depr, '/', $url);
|
||||||
|
}
|
||||||
$result = self::parseRoute($url);
|
$result = self::parseRoute($url);
|
||||||
if (!empty($result['var'])) {
|
if (!empty($result['var'])) {
|
||||||
$_GET = array_merge($result['var'], $_GET);
|
$_GET = array_merge($result['var'], $_GET);
|
||||||
|
|||||||
Reference in New Issue
Block a user