From 83f6bd0d666b1402dcff8beb7dcd8fe193ec8618 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 27 Jul 2017 15:53:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84=E9=94=99=E8=AF=AF=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 9 ++++++--- library/think/Loader.php | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index b7d59691..615be241 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -11,6 +11,7 @@ namespace think; +use think\exception\ClassNotFoundException; use think\exception\HttpException; use think\exception\HttpResponseException; use think\exception\RouteNotFoundException; @@ -383,10 +384,12 @@ class App // 监听module_init Hook::listen('module_init', $request); - $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']); - if (is_null($instance)) { - throw new HttpException(404, 'controller not exists:' . Loader::parseName($controller, 1)); + try { + $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']); + } catch (ClassNotFoundException $e) { + throw new HttpException(404, 'controller not exists:' . $e->getClass()); } + // 获取当前操作名 $action = $actionName . $config['action_suffix']; diff --git a/library/think/Loader.php b/library/think/Loader.php index a0727fef..62e876e5 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -400,7 +400,7 @@ class Loader * @param string $layer 控制层名称 * @param bool $appendSuffix 是否添加类名后缀 * @param string $empty 空控制器名称 - * @return Object|false + * @return Object * @throws ClassNotFoundException */ public static function controller($name, $layer = 'controller', $appendSuffix = false, $empty = '') @@ -420,6 +420,8 @@ class Loader return App::invokeClass($class); } elseif ($empty && class_exists($emptyClass = self::parseClass($module, $layer, $empty, $appendSuffix))) { return new $emptyClass(Request::instance()); + } else { + throw new ClassNotFoundException('class not exists:' . $class, $class); } }