mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
修正route类的parseURL解析
This commit is contained in:
@@ -71,7 +71,7 @@ class App
|
|||||||
// 执行操作
|
// 执行操作
|
||||||
if (!preg_match('/^[A-Za-z](\/|\.|\w)*$/', CONTROLLER_NAME)) {
|
if (!preg_match('/^[A-Za-z](\/|\.|\w)*$/', CONTROLLER_NAME)) {
|
||||||
// 安全检测
|
// 安全检测
|
||||||
throw new Exception('[ ' . MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . Loader::parseName(str_replace('.', '\\', CONTROLLER_NAME), 1) . ' ] not exists');
|
throw new Exception('class [ ' . MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . Loader::parseName(str_replace('.', '\\', CONTROLLER_NAME), 1) . ' ] not exists');
|
||||||
}
|
}
|
||||||
if ($config['action_bind_class']) {
|
if ($config['action_bind_class']) {
|
||||||
$class = self::bindActionClass($config['empty_controller']);
|
$class = self::bindActionClass($config['empty_controller']);
|
||||||
@@ -84,6 +84,9 @@ class App
|
|||||||
$action = ACTION_NAME . $config['action_suffix'];
|
$action = ACTION_NAME . $config['action_suffix'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$instance) {
|
||||||
|
throw new Exception('class [ ' . MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . Loader::parseName(str_replace('.', '\\', CONTROLLER_NAME), 1) . ' ] not exists');
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// 操作方法开始监听
|
// 操作方法开始监听
|
||||||
$call = [$instance, $action];
|
$call = [$instance, $action];
|
||||||
@@ -119,7 +122,7 @@ class App
|
|||||||
$method = new \ReflectionMethod($instance, '_empty');
|
$method = new \ReflectionMethod($instance, '_empty');
|
||||||
$method->invokeArgs($instance, [$action, '']);
|
$method->invokeArgs($instance, [$action, '']);
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('[ ' . (new \ReflectionClass($instance))->getName() . ':' . $action . ' ] not exists ', 404);
|
throw new Exception('method [ ' . (new \ReflectionClass($instance))->getName() . '->' . $action . ' ] not exists ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,10 +125,16 @@ class Error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$type = Config::get('default_return_type');
|
||||||
|
if ('html' == $type) {
|
||||||
|
include Config::get('exception_tmpl');
|
||||||
|
} else {
|
||||||
// 异常信息输出监听
|
// 异常信息输出监听
|
||||||
Hook::listen('error_output', $e);
|
Hook::listen('error_output', $e);
|
||||||
// 输出异常内容
|
// 输出异常内容
|
||||||
Response::returnData($e, Config::get('default_return_type'));
|
Response::returnData($e, $type);
|
||||||
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ class Route
|
|||||||
if ('/' != $depr) {
|
if ('/' != $depr) {
|
||||||
$url = str_replace($depr, '/', $url);
|
$url = str_replace($depr, '/', $url);
|
||||||
}
|
}
|
||||||
$result = self::parseRoute($url);
|
$result = self::parseRoute($url, true);
|
||||||
if (!empty($result['var'])) {
|
if (!empty($result['var'])) {
|
||||||
$_GET = array_merge($result['var'], $_GET);
|
$_GET = array_merge($result['var'], $_GET);
|
||||||
}
|
}
|
||||||
@@ -433,7 +433,7 @@ class Route
|
|||||||
|
|
||||||
// 解析规范的路由地址
|
// 解析规范的路由地址
|
||||||
// 地址格式 [模块/控制器/操作?]参数1=值1&参数2=值2...
|
// 地址格式 [模块/控制器/操作?]参数1=值1&参数2=值2...
|
||||||
private static function parseRoute($url)
|
private static function parseRoute($url, $reverse = false)
|
||||||
{
|
{
|
||||||
$var = [];
|
$var = [];
|
||||||
if (false !== strpos($url, '?')) {
|
if (false !== strpos($url, '?')) {
|
||||||
@@ -444,10 +444,13 @@ class Route
|
|||||||
} elseif (strpos($url, '/')) {
|
} elseif (strpos($url, '/')) {
|
||||||
// [模块/控制器/操作]
|
// [模块/控制器/操作]
|
||||||
$path = explode('/', $url, 4);
|
$path = explode('/', $url, 4);
|
||||||
} else {
|
} elseif (false !== strpos($url, '=')) {
|
||||||
// 参数1=值1&参数2=值2...
|
// 参数1=值1&参数2=值2...
|
||||||
parse_str($url, $var);
|
parse_str($url, $var);
|
||||||
|
} else {
|
||||||
|
$path = [$url];
|
||||||
}
|
}
|
||||||
|
$route = [null, null, null];
|
||||||
if (isset($path)) {
|
if (isset($path)) {
|
||||||
// 解析path额外的参数
|
// 解析path额外的参数
|
||||||
if (!empty($path[3])) {
|
if (!empty($path[3])) {
|
||||||
@@ -456,12 +459,19 @@ class Route
|
|||||||
}, array_pop($path));
|
}, array_pop($path));
|
||||||
}
|
}
|
||||||
// 解析[模块/控制器/操作]
|
// 解析[模块/控制器/操作]
|
||||||
|
if ($reverse) {
|
||||||
|
$module = array_shift($path);
|
||||||
|
$controller = !empty($path) ? array_shift($path) : null;
|
||||||
|
$action = !empty($path) ? array_shift($path) : null;
|
||||||
|
} else {
|
||||||
$action = array_pop($path);
|
$action = array_pop($path);
|
||||||
$action = '[rest]' == $action ? REQUEST_METHOD : $action;
|
|
||||||
$controller = !empty($path) ? array_pop($path) : null;
|
$controller = !empty($path) ? array_pop($path) : null;
|
||||||
$module = !empty($path) ? array_pop($path) : null;
|
$module = !empty($path) ? array_pop($path) : null;
|
||||||
}
|
}
|
||||||
return ['route' => [$module, $controller, $action], 'var' => $var];
|
$action = '[rest]' == $action ? REQUEST_METHOD : $action;
|
||||||
|
$route = [$module, $controller, $action];
|
||||||
|
}
|
||||||
|
return ['route' => $route, 'var' => $var];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测URL和规则路由是否匹配
|
// 检测URL和规则路由是否匹配
|
||||||
|
|||||||
Reference in New Issue
Block a user