From 188e64abf667404687b7d3ab0ca1abb4f8a7b42b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 24 May 2016 22:08:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88APP=5FHOOK=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=20=E9=BB=98=E8=AE=A4=E5=BC=80=E5=90=AF=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 3 +-- library/think/App.php | 10 +++++----- library/think/Log.php | 2 +- library/think/Response.php | 2 +- library/think/Route.php | 2 +- library/think/View.php | 2 +- library/think/log/driver/Trace.php | 6 ++++-- mode/console/App.php | 4 ++-- start.php | 5 +---- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/base.php b/base.php index f12ae4ac..c9b54fba 100644 --- a/base.php +++ b/base.php @@ -44,8 +44,7 @@ defined('APP_AUTO_RUN') or define('APP_AUTO_RUN', true); // 是否自动运行 defined('APP_ROUTE_ON') or define('APP_ROUTE_ON', true); // 是否允许路由 defined('APP_ROUTE_MUST') or define('APP_ROUTE_MUST', true); // 是否严格检查路由 defined('CLASS_APPEND_SUFFIX') or define('CLASS_APPEND_SUFFIX', false); // 是否追加类名后缀 -// 应用模式 默认为普通模式 -defined('APP_MODE') or define('APP_MODE', function_exists('saeAutoLoader') ? 'sae' : 'common'); +defined('APP_MODE') or define('APP_MODE', 'common'); // 应用模式 默认为普通模式 // 环境常量 define('IS_CGI', strpos(PHP_SAPI, 'cgi') === 0 ? 1 : 0); diff --git a/library/think/App.php b/library/think/App.php index 47b0c92c..2e7f4247 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -71,7 +71,7 @@ class App date_default_timezone_set($config['default_timezone']); // 监听app_init - APP_HOOK && Hook::listen('app_init'); + Hook::listen('app_init'); // 开启多语言机制 if ($config['lang_switch_on']) { @@ -93,7 +93,7 @@ class App // 记录路由信息 APP_DEBUG && Log::record('[ ROUTE ] ' . var_export($dispatch, true), 'info'); // 监听app_begin - APP_HOOK && Hook::listen('app_begin', $dispatch); + Hook::listen('app_begin', $dispatch); try { switch ($dispatch['type']) { case 'redirect': @@ -127,7 +127,7 @@ class App } // 监听app_end - APP_HOOK && Hook::listen('app_end', $data); + Hook::listen('app_end', $data); // 输出数据到客户端 if ($data instanceof Response) { @@ -266,7 +266,7 @@ class App try { // 操作方法开始监听 $call = [$instance, $action]; - APP_HOOK && Hook::listen('action_begin', $call); + Hook::listen('action_begin', $call); if (!preg_match('/^[A-Za-z](\w)*$/', $action)) { // 非法操作 throw new \ReflectionException('illegal action name :' . ACTION_NAME); @@ -325,7 +325,7 @@ class App } // 加载行为扩展文件 - if (APP_HOOK && is_file($path . 'tags' . EXT)) { + if (is_file($path . 'tags' . EXT)) { Hook::import(include $path . 'tags' . EXT); } diff --git a/library/think/Log.php b/library/think/Log.php index a7cb4ec9..ffa03fd4 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -126,7 +126,7 @@ class Log $log[] = ['type' => $type, 'msg' => $msg]; // 监听log_write - APP_HOOK && Hook::listen('log_write', $log); + Hook::listen('log_write', $log); if (is_null(self::$driver)) { self::init(Config::get('log')); } diff --git a/library/think/Response.php b/library/think/Response.php index 57aa426e..13a5dc76 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -101,7 +101,7 @@ class Response $data = $this->output($data); // 监听response_data - APP_HOOK && Hook::listen('response_data', $data); + Hook::listen('response_data', $data); // 发送头部信息 if (!headers_sent() && !empty($this->header)) { diff --git a/library/think/Route.php b/library/think/Route.php index 395e2f49..372e9582 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -750,7 +750,7 @@ class Route // 请求类型检测 if ((isset($option['method']) && false === stripos($option['method'], REQUEST_METHOD)) || (isset($option['ext']) && false === stripos($option['ext'], __EXT__)) // 伪静态后缀检测 - || (isset($option['domain']) && !in_array($option['domain'], [HTTP_HOST, self::$subDomain])) // 域名检测 + || (isset($option['domain']) && !in_array($option['domain'], [$_SERVER['HTTP_HOST'], self::$subDomain])) // 域名检测 || (!empty($option['https']) && !$request->isSsl()) // https检测 || (!empty($option['before_behavior']) && false === Hook::exec($option['before_behavior'], $url)) // 行为检测 || (!empty($option['callback']) && is_callable($option['callback']) && false === call_user_func($option['callback'])) // 自定义检测 diff --git a/library/think/View.php b/library/think/View.php index 2cd90226..84f2e428 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -117,7 +117,7 @@ class View // 获取并清空缓存 $content = ob_get_clean(); // 内容过滤标签 - APP_HOOK && Hook::listen('view_filter', $content); + Hook::listen('view_filter', $content); // 允许用户自定义模板的字符串替换 $replace = array_merge($this->replace, $replace); if (!empty($replace)) { diff --git a/library/think/log/driver/Trace.php b/library/think/log/driver/Trace.php index e4565c83..d0501b2f 100644 --- a/library/think/log/driver/Trace.php +++ b/library/think/log/driver/Trace.php @@ -11,7 +11,9 @@ namespace think\log\driver; +use think\Cache; use think\Config; +use think\Db; use think\Debug; /** @@ -53,8 +55,8 @@ class Trace $base = [ '请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '运行时间' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 内存消耗:{$mem}kb 文件加载:" . count(get_included_files()), - '查询信息' => \think\Db::$queryTimes . ' queries ' . \think\Db::$executeTimes . ' writes ', - '缓存信息' => \think\Cache::$readTimes . ' reads,' . \think\Cache::$writeTimes . ' writes', + '查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ', + '缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes', '配置加载' => count(Config::get()), ]; diff --git a/mode/console/App.php b/mode/console/App.php index fd19be16..01594d58 100644 --- a/mode/console/App.php +++ b/mode/console/App.php @@ -73,7 +73,7 @@ class App } // 加载行为扩展文件 - if (APP_HOOK && is_file(APP_PATH . 'tags' . EXT)) { + if (is_file(APP_PATH . 'tags' . EXT)) { Hook::import(include APP_PATH . 'tags' . EXT); } @@ -102,6 +102,6 @@ class App date_default_timezone_set($config['default_timezone']); // 监听app_init - APP_HOOK && Hook::listen('app_init'); + Hook::listen('app_init'); } } \ No newline at end of file diff --git a/start.php b/start.php index 5ad6f069..b8fa8b9b 100644 --- a/start.php +++ b/start.php @@ -54,11 +54,8 @@ if (isset($mode['config'])) { is_array($mode['config']) ? Config::set($mode['config']) : Config::load($mode['config']); } -// 是否开启HOOK -defined('APP_HOOK') or define('APP_HOOK', false); - // 加载模式行为定义 -if (APP_HOOK && isset($mode['tags'])) { +if (isset($mode['tags'])) { Hook::import($mode['tags']); }