From 2694a640ff89d21017bca2c45b2740657596e5ab Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Dec 2015 23:11:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1=E9=97=AD?= =?UTF-8?q?=E5=8C=85=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 2 +- library/think/app.php | 44 +++++++++++++++++--------------------- library/think/config.php | 2 +- library/think/response.php | 2 +- library/think/route.php | 19 +++++++--------- 5 files changed, 31 insertions(+), 38 deletions(-) diff --git a/convention.php b/convention.php index 04fc4034..7ea84e95 100644 --- a/convention.php +++ b/convention.php @@ -2,7 +2,7 @@ return [ // 应用模式状态 - 'app_status' => 'debug', + 'app_status' => '', // PATHINFO变量名 用于兼容模式 'var_pathinfo' => 's', // 兼容PATH_INFO获取 diff --git a/library/think/app.php b/library/think/app.php index 152f95bd..699758f9 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -109,11 +109,9 @@ class App // 操作方法执行完成监听 Hook::listen('action_end', $data); // 返回数据 - $data = Response::returnData($data, $config['default_return_type']); + Response::returnData($data, $config['default_return_type']); if ($config['response_exit']) { - exit($data); - } else { - echo $data; + exit; } } else { // 操作方法不是Public 抛出异常 @@ -128,7 +126,6 @@ class App throw new Exception('[ ' . (new \ReflectionClass($instance))->getName() . ':' . $action . ' ] not exists ', 404); } } - return; } // 操作绑定到类:模块\controller\控制器\操作类 @@ -152,6 +149,7 @@ class App return $class; } + // 获取操作方法的参数绑定 private static function getBindParams($method, $paramsBindType) { switch ($_SERVER['REQUEST_METHOD']) { @@ -179,41 +177,39 @@ class App } return $args; } - /** - * 初始化模块 - * @access private - * @return void - */ + + // 初始化模块 private static function initModule($module, &$config) { - // 加载初始化文件 - if (is_file(APP_PATH . $module . '/init' . EXT)) { - include APP_PATH . $module . '/init' . EXT; - } else { + // 定位模块目录 + $module = COMMON_MODULE == $module ? '' : $module . '/'; - // 定位模块目录 - $module = COMMON_MODULE == $module ? '' : $module . '/'; + // 加载初始化文件 + if (is_file(APP_PATH . $module . 'init' . EXT)) { + include APP_PATH . $module . 'init' . EXT; + } else { + $path = APP_PATH . $module; // 加载模块配置 $config = Config::load($module . 'config'); // 加载应用状态配置 - if ($config['app_status'] && is_file(APP_PATH . $module . $config['app_status'] . EXT)) { + if ($config['app_status']) { $config = Config::load($module . $config['app_status']); } // 加载别名文件 - if (is_file(APP_PATH . $module . 'alias' . EXT)) { - Loader::addMap(include APP_PATH . $module . 'alias' . EXT); + if (is_file($path . 'alias' . EXT)) { + Loader::addMap(include $path . 'alias' . EXT); } // 加载行为扩展文件 - if (is_file(APP_PATH . $module . 'tags' . EXT)) { - Hook::import(include APP_PATH . $module . 'tags' . EXT); + if (is_file($path . 'tags' . EXT)) { + Hook::import(include $path . 'tags' . EXT); } // 加载公共文件 - if (is_file(APP_PATH . $module . 'common' . EXT)) { - include APP_PATH . $module . 'common' . EXT; + if (is_file($path . 'common' . EXT)) { + include $path . 'common' . EXT; } } } @@ -236,7 +232,7 @@ class App // 检测域名部署 if (!IS_CLI && !empty($config['domain_deploy'])) { - Route::checkDomain(); + Route::checkDomain($config['domain_rules']); } // 监听path_info diff --git a/library/think/config.php b/library/think/config.php index 415b8c0d..31cfff5c 100644 --- a/library/think/config.php +++ b/library/think/config.php @@ -37,7 +37,7 @@ class Config // 加载配置文件 public static function load($file, $name = '', $range = '') { - $file = is_file($file) ? $file : APP_PATH . $file . EXT; + $file = strpos($file, '.') ? $file : APP_PATH . $file . EXT; return is_file($file) ? self::set(include $file, $name, $range) : self::$config[$range]; } diff --git a/library/think/response.php b/library/think/response.php index a90f665f..f01559d8 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -55,7 +55,7 @@ class Response $data = $handler . '(' . Transform::jsonEncode($data) . ');'; break; } - return $data; + echo $data; } /** diff --git a/library/think/route.php b/library/think/route.php index aa8d7bf1..08cbcb93 100644 --- a/library/think/route.php +++ b/library/think/route.php @@ -111,11 +111,11 @@ class Route } // 检测子域名部署 - public static function checkDomain() + public static function checkDomain($rules = '') { + $rules = $rules ?: self::$domain; // 开启子域名部署 支持二级和三级域名 - if (!empty(self::$domain)) { - $rules = self::$domain; + if (!empty($rules)) { if (isset($rules[$_SERVER['HTTP_HOST']])) { // 完整域名或者IP配置 $rule = $rules[$_SERVER['HTTP_HOST']]; @@ -339,7 +339,7 @@ class Route $args[] = $param->getDefaultValue(); } } - $reflect->invokeArgs($args); + return $reflect->invokeArgs($args); } // 执行规则匹配下的闭包方法 支持参数调用 @@ -356,7 +356,7 @@ class Route $args[] = $param->getDefaultValue(); } } - $reflect->invokeArgs($args); + return $reflect->invokeArgs($args); } // 解析模块的URL地址 [模块/]控制器/操作 @@ -365,13 +365,10 @@ class Route if ('/' == $url) { return [null, null, null]; } - $paths = explode('/', $url); - - $module = defined('BIND_MODULE') ? BIND_MODULE : array_shift($paths); - + $paths = explode('/', $url); + $module = defined('BIND_MODULE') ? BIND_MODULE : array_shift($paths); $controller = defined('BIND_CONTROLLER') ? BIND_CONTROLLER : array_shift($paths); - - $action = $paths ? array_shift($paths) : null; + $action = $paths ? array_shift($paths) : null; // 解析剩余的URL参数 $var = [];