From 65be8f094cffd2cb2b526e4b5b2d276566f91ecb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 10 Dec 2015 21:56:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0APP=5FHOOK=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=20=E7=94=A8=E4=BA=8E=E6=98=AF=E5=90=A6=E5=90=AF=E7=94=A8=20hoo?= =?UTF-8?q?k?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 7 ++++--- convention.php | 2 +- library/think/app.php | 29 ++++++++++++----------------- start.php | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/base.php b/base.php index e60d05b2..ecf38b17 100644 --- a/base.php +++ b/base.php @@ -32,6 +32,7 @@ defined('MODEL_LAYER') or define('MODEL_LAYER', 'model'); defined('VIEW_LAYER') or define('VIEW_LAYER', 'view'); defined('CONTROLLER_LAYER') or define('CONTROLLER_LAYER', 'controller'); defined('APP_DEBUG') or define('APP_DEBUG', false); // 是否调试模式 +defined('APP_HOOK') or define('APP_HOOK', false); // 是否开启HOOK defined('ENV_PREFIX') or define('ENV_PREFIX', 'T_'); // 环境变量的配置前缀 defined('IS_API') or define('IS_API', false); // 是否API接口 defined('SLOG_ON') or define('SLOG_ON', false); // 是否开启socketLog @@ -313,7 +314,7 @@ function S($name, $value = '', $options = null) * @param string $css 样式 * @return void|array */ -function trace($log,$level='log',$css='') +function trace($log, $level = 'log', $css = '') { - think\Slog::record($level,$log,$css); -} \ No newline at end of file + think\Slog::record($level, $log, $css); +} diff --git a/convention.php b/convention.php index 22429e0c..14deafc7 100644 --- a/convention.php +++ b/convention.php @@ -48,7 +48,7 @@ return [ // PATHINFO变量名 用于兼容模式 'var_pathinfo' => 's', // 兼容PATH_INFO获取 - 'pathinfo_fetch' => 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL', + 'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'], // pathinfo分隔符 'pathinfo_depr' => '/', // 获取当前页面地址的系统变量 默认为REQUEST_URI diff --git a/library/think/app.php b/library/think/app.php index 2157685d..8ca87dc5 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -55,10 +55,10 @@ class App Lang::load(THINK_PATH . 'Lang/' . $lang . EXT); // 监听app_init - Hook::listen('app_init'); + APP_HOOK && Hook::listen('app_init'); - // 启动session - if (!IS_CLI && $config['use_session']) { + // 启动session API CLI 不开启 + if (!IS_CLI && !IS_API && $config['use_session']) { Session::init($config['session']); } @@ -66,7 +66,7 @@ class App self::dispatch($config); // 监听app_run - Hook::listen('app_run'); + APP_HOOK && Hook::listen('app_run'); // 执行操作 if (!preg_match('/^[A-Za-z](\/|\.|\w)*$/', CONTROLLER_NAME)) { @@ -90,7 +90,7 @@ class App try { // 操作方法开始监听 $call = [$instance, $action]; - Hook::listen('action_begin', $call); + APP_HOOK && Hook::listen('action_begin', $call); if (!preg_match('/^[A-Za-z](\w)*$/', $action)) { // 非法操作 throw new \ReflectionException(); @@ -109,7 +109,7 @@ class App $data = $method->invoke($instance); } // 操作方法执行完成监听 - Hook::listen('action_end', $data); + APP_HOOK && Hook::listen('action_end', $data); // 返回数据 Response::returnData($data, $config['default_return_type'], $config['response_exit']); } else { @@ -202,7 +202,7 @@ class App } // 加载行为扩展文件 - if (is_file($path . 'tags' . EXT)) { + if (APP_HOOK && is_file($path . 'tags' . EXT)) { Hook::import(include $path . 'tags' . EXT); } @@ -242,16 +242,11 @@ class App } // 监听path_info - Hook::listen('path_info'); + APP_HOOK && Hook::listen('path_info'); // 分析PATHINFO信息 if (!isset($_SERVER['PATH_INFO']) && $_SERVER['SCRIPT_NAME'] != $_SERVER['PHP_SELF']) { - $types = explode(',', $config['pathinfo_fetch']); - foreach ($types as $type) { - if (0 === strpos($type, ':')) { - // 支持函数判断 - $_SERVER['PATH_INFO'] = call_user_func(substr($type, 1)); - break; - } elseif (!empty($_SERVER[$type])) { + foreach ($config['pathinfo_fetch'] as $type) { + if (!empty($_SERVER[$type])) { $_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME'])) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; break; @@ -273,7 +268,7 @@ class App define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION))); if (__INFO__) { if ($config['url_deny_suffix'] && preg_match('/\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) { - throw new Exception('URL_SUFFIX_DENY'); + throw new Exception('url suffix deny'); } $depr = $config['pathinfo_depr']; // 还原劫持后真实pathinfo @@ -323,7 +318,7 @@ class App // 模块初始化 if (MODULE_NAME && !in_array(MODULE_NAME, $config['deny_module_list']) && is_dir(APP_PATH . MODULE_NAME)) { - Hook::listen('app_begin'); + APP_HOOK && Hook::listen('app_begin'); define('MODULE_PATH', APP_PATH . MODULE_NAME . DS); define('VIEW_PATH', MODULE_PATH . VIEW_LAYER . DS); diff --git a/start.php b/start.php index 49092f85..bb9a0464 100644 --- a/start.php +++ b/start.php @@ -38,7 +38,7 @@ if (isset($mode['config'])) { } // 加载模式行为定义 -if (isset($mode['tags'])) { +if (APP_HOOK && isset($mode['tags'])) { Hook::import(is_array($mode['tags']) ? $mode['tags'] : include $mode['tags']); }