From 56cffea8171cacf10f06116e19286245ac18706a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 10 Jan 2016 08:52:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=88=B0class=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20=E8=B7=AF=E7=94=B1=E5=88=B0=20callable=20=E9=80=82?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=9B=B4=E5=A4=9A=E7=9A=84=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 6 +++--- library/think/Route.php | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 98d5a7b0..2436c027 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -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': // 规则闭包 diff --git a/library/think/Route.php b/library/think/Route.php index 6e08c0fd..54489b09 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -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];