mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
路由到class 改为 路由到 callable 适用于更多的回调机制
This commit is contained in:
@@ -97,9 +97,9 @@ class App
|
||||
// 执行控制器操作
|
||||
$data = Loader::action(self::$dispatch['controller'], self::$dispatch['params']);
|
||||
break;
|
||||
case 'class':
|
||||
// 执行类,例如行为
|
||||
$data = Hook::exec(self::$dispatch['class'], self::$dispatch['method'], self::$dispatch['params']);
|
||||
case 'callable':
|
||||
// 执行回调方法
|
||||
$data = call_user_func_array(self::$dispatch['callable'], self::$dispatch['params']);
|
||||
break;
|
||||
case 'closure':
|
||||
// 规则闭包
|
||||
|
||||
@@ -318,17 +318,17 @@ class Route
|
||||
if (isset($array[1])) {
|
||||
self::parseUrlParams($array[1]);
|
||||
}
|
||||
$return = ['type' => 'class', 'class' => self::$bind['class'], 'method' => $array[0] ?: '', 'params' => []];
|
||||
$return = ['type' => 'callable', 'callable' => [self::$bind['class'], $array[0] ?: Config::get('default_action')], 'params' => []];
|
||||
break;
|
||||
case 'namespace':
|
||||
// 绑定到命名空间
|
||||
$array = explode('/', $url, 3);
|
||||
$class = isset($array[0]) ? $array[0] : 'index';
|
||||
$method = isset($array[1]) ? $array[1] : 'index';
|
||||
$class = isset($array[0]) ? $array[0] : Config::get('default_controller');
|
||||
$method = isset($array[1]) ? $array[1] : Config::get('default_action');
|
||||
if (isset($array[2])) {
|
||||
self::parseUrlParams($array[2]);
|
||||
}
|
||||
$return = ['type' => 'class', 'class' => self::$bind['namespace'] . '\\' . $class, 'method' => $method, 'params' => []];
|
||||
$return = ['type' => 'callable', 'callable' => [self::$bind['namespace'] . '\\' . $class, $method], 'params' => []];
|
||||
break;
|
||||
case 'module':
|
||||
// 如果有模块/控制器绑定 针对路由到 模块/控制器 有效
|
||||
@@ -580,14 +580,12 @@ class Route
|
||||
$item = substr($item, 1, -1);
|
||||
}
|
||||
if (0 === strpos($item, ':')) {
|
||||
|
||||
if (strpos($item, '\\')) {
|
||||
$var = substr($item, 1, -2);
|
||||
} else {
|
||||
$var = substr($item, 1);
|
||||
}
|
||||
$matches[$var] = array_shift($paths);
|
||||
|
||||
} else {
|
||||
// 过滤URL中的静态变量
|
||||
array_shift($paths);
|
||||
@@ -602,8 +600,8 @@ class Route
|
||||
}
|
||||
$result = ['type' => 'redirect', 'url' => $url, 'status' => (is_array($route) && isset($route[1])) ? $route[1] : 301];
|
||||
} elseif (0 === strpos($url, '\\')) {
|
||||
// 路由到行为
|
||||
$result = ['type' => 'class', 'class' => $url, 'method' => isset($route[1]) ? $route[1] : '', 'params' => $matches];
|
||||
// 路由到回调
|
||||
$result = ['type' => 'callable', 'callable' => $route, 'params' => $matches];
|
||||
} elseif (0 === strpos($url, '@')) {
|
||||
// 路由到控制器
|
||||
$result = ['type' => 'controller', 'controller' => substr($url, 1), 'params' => $matches];
|
||||
|
||||
Reference in New Issue
Block a user