diff --git a/core/convention.php b/core/convention.php index faf7571b..6a841a30 100644 --- a/core/convention.php +++ b/core/convention.php @@ -15,6 +15,8 @@ return [ 'app_status' => '', // 是否支持多模块 'app_multi_module' => true, + // 入口自动绑定模块 + 'auto_bind_module' => false, // 注册的根命名空间 'root_namespace' => [], // 扩展配置文件 diff --git a/core/library/think/App.php b/core/library/think/App.php index c0fed042..a9236f6f 100644 --- a/core/library/think/App.php +++ b/core/library/think/App.php @@ -79,6 +79,17 @@ class App is_null($request) && $request = Request::instance(); $config = self::initCommon(); + if (defined('BIND_MODULE')) { + // 模块/控制器绑定 + BIND_MODULE && Route::bind(BIND_MODULE); + } elseif ($config['auto_bind_module']) { + // 入口自动绑定 + $name = pathinfo($request->baseFile(), PATHINFO_FILENAME); + if ($name && 'index' != $name && is_dir(APP_PATH . $name)) { + Route::bind($name); + } + } + $request->filter($config['default_filter']); try { @@ -102,8 +113,13 @@ class App // 记录当前调度信息 $request->dispatch($dispatch); - // 记录路由信息 - self::$debug && Log::record('[ ROUTE ] ' . var_export($dispatch, true), 'info'); + // 记录路由和请求信息 + if (self::$debug) { + Log::record('[ ROUTE ] ' . var_export($dispatch, true), 'info'); + Log::record('[ HEADER ] ' . var_export($request->header(), true), 'info'); + Log::record('[ PARAM ] ' . var_export($request->param(), true), 'info'); + } + // 监听app_begin Hook::listen('app_begin', $dispatch); @@ -156,11 +172,6 @@ class App // 监听app_end Hook::listen('app_end', $response); - // Trace调试注入 - if (Config::get('app_trace')) { - Debug::inject($response); - } - return $response; } @@ -322,7 +333,7 @@ class App try { $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:' . $controller); + throw new HttpException(404, 'controller not exists:' . Loader::parseName($controller, 1)); } // 获取当前操作名 $action = $actionName . $config['action_suffix']; @@ -374,7 +385,7 @@ class App } } - // 应用命名空间 + // 注册应用命名空间 self::$namespace = $config['app_namespace']; Loader::addNamespace($config['app_namespace'], APP_PATH); if (!empty($config['root_namespace'])) { diff --git a/core/library/think/Debug.php b/core/library/think/Debug.php index 28b6ab1e..e36a764e 100644 --- a/core/library/think/Debug.php +++ b/core/library/think/Debug.php @@ -159,9 +159,10 @@ class Debug * @param mixed $var 变量 * @param boolean $echo 是否输出 默认为true 如果为false 则返回输出字符串 * @param string $label 标签 默认为空 + * @param integer $flags htmlspecialchars flags * @return void|string */ - public static function dump($var, $echo = true, $label = null) + public static function dump($var, $echo = true, $label = null, $flags = ENT_SUBSTITUTE) { $label = (null === $label) ? '' : rtrim($label) . ':'; ob_start(); @@ -172,7 +173,7 @@ class Debug $output = PHP_EOL . $label . $output . PHP_EOL; } else { if (!extension_loaded('xdebug')) { - $output = htmlspecialchars($output, ENT_QUOTES); + $output = htmlspecialchars($output, $flags); } $output = '
' . $label . $output . ''; } @@ -184,14 +185,12 @@ class Debug } } - public static function inject(Response $response) + public static function inject(Response $response, &$content) { - $config = Config::get('trace'); - $type = isset($config['type']) ? $config['type'] : 'Html'; - $request = Request::instance(); - $accept = $request->header('accept'); - $contentType = $response->getHeader('Content-Type'); - $class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type); + $config = Config::get('trace'); + $type = isset($config['type']) ? $config['type'] : 'Html'; + $request = Request::instance(); + $class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type); unset($config['type']); if (class_exists($class)) { $trace = new $class($config); @@ -205,14 +204,12 @@ class Debug $output = $trace->output($response, Log::getLog()); if (is_string($output)) { // trace调试信息注入 - $content = $response->getContent(); - $pos = strripos($content, '