From 09c6be5dd3b47b9b7f5581c5e777c2e6c5947d1f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 10 Jan 2016 09:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E7=BB=91=E5=AE=9A=E5=88=B0?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E5=92=8C=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD=20callable=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 6 +++++- library/think/Route.php | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 2436c027..d4e50072 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -99,7 +99,11 @@ class App break; case 'callable': // 执行回调方法 - $data = call_user_func_array(self::$dispatch['callable'], self::$dispatch['params']); + if (is_callable(self::$dispatch['callable'])) { + $data = call_user_func_array(self::$dispatch['callable'], self::$dispatch['params']); + } else { + throw new Exception('not callable : ' . (is_array(self::$dispatch['callable']) ? implode('->', self::$dispatch['callable']) : self::$dispatch['callable']), 10009); + } break; case 'closure': // 规则闭包 diff --git a/library/think/Route.php b/library/think/Route.php index 54489b09..093286d7 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -315,7 +315,7 @@ class Route case 'class': // 绑定到类 $array = explode('/', $url, 2); - if (isset($array[1])) { + if (!empty($array[1])) { self::parseUrlParams($array[1]); } $return = ['type' => 'callable', 'callable' => [self::$bind['class'], $array[0] ?: Config::get('default_action')], 'params' => []]; @@ -323,9 +323,9 @@ class Route case 'namespace': // 绑定到命名空间 $array = explode('/', $url, 3); - $class = isset($array[0]) ? $array[0] : Config::get('default_controller'); - $method = isset($array[1]) ? $array[1] : Config::get('default_action'); - if (isset($array[2])) { + $class = !empty($array[0]) ? $array[0] : Config::get('default_controller'); + $method = !empty($array[1]) ? $array[1] : Config::get('default_action'); + if (!empty($array[2])) { self::parseUrlParams($array[2]); } $return = ['type' => 'callable', 'callable' => [self::$bind['namespace'] . '\\' . $class, $method], 'params' => []];