mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
增加APP_HOOK常量 用于是否启用 hook
This commit is contained in:
1
base.php
1
base.php
@@ -32,6 +32,7 @@ defined('MODEL_LAYER') or define('MODEL_LAYER', 'model');
|
|||||||
defined('VIEW_LAYER') or define('VIEW_LAYER', 'view');
|
defined('VIEW_LAYER') or define('VIEW_LAYER', 'view');
|
||||||
defined('CONTROLLER_LAYER') or define('CONTROLLER_LAYER', 'controller');
|
defined('CONTROLLER_LAYER') or define('CONTROLLER_LAYER', 'controller');
|
||||||
defined('APP_DEBUG') or define('APP_DEBUG', false); // 是否调试模式
|
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('ENV_PREFIX') or define('ENV_PREFIX', 'T_'); // 环境变量的配置前缀
|
||||||
defined('IS_API') or define('IS_API', false); // 是否API接口
|
defined('IS_API') or define('IS_API', false); // 是否API接口
|
||||||
defined('SLOG_ON') or define('SLOG_ON', false); // 是否开启socketLog
|
defined('SLOG_ON') or define('SLOG_ON', false); // 是否开启socketLog
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ return [
|
|||||||
// PATHINFO变量名 用于兼容模式
|
// PATHINFO变量名 用于兼容模式
|
||||||
'var_pathinfo' => 's',
|
'var_pathinfo' => 's',
|
||||||
// 兼容PATH_INFO获取
|
// 兼容PATH_INFO获取
|
||||||
'pathinfo_fetch' => 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL',
|
'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
|
||||||
// pathinfo分隔符
|
// pathinfo分隔符
|
||||||
'pathinfo_depr' => '/',
|
'pathinfo_depr' => '/',
|
||||||
// 获取当前页面地址的系统变量 默认为REQUEST_URI
|
// 获取当前页面地址的系统变量 默认为REQUEST_URI
|
||||||
|
|||||||
@@ -55,10 +55,10 @@ class App
|
|||||||
Lang::load(THINK_PATH . 'Lang/' . $lang . EXT);
|
Lang::load(THINK_PATH . 'Lang/' . $lang . EXT);
|
||||||
|
|
||||||
// 监听app_init
|
// 监听app_init
|
||||||
Hook::listen('app_init');
|
APP_HOOK && Hook::listen('app_init');
|
||||||
|
|
||||||
// 启动session
|
// 启动session API CLI 不开启
|
||||||
if (!IS_CLI && $config['use_session']) {
|
if (!IS_CLI && !IS_API && $config['use_session']) {
|
||||||
Session::init($config['session']);
|
Session::init($config['session']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ class App
|
|||||||
self::dispatch($config);
|
self::dispatch($config);
|
||||||
|
|
||||||
// 监听app_run
|
// 监听app_run
|
||||||
Hook::listen('app_run');
|
APP_HOOK && Hook::listen('app_run');
|
||||||
|
|
||||||
// 执行操作
|
// 执行操作
|
||||||
if (!preg_match('/^[A-Za-z](\/|\.|\w)*$/', CONTROLLER_NAME)) {
|
if (!preg_match('/^[A-Za-z](\/|\.|\w)*$/', CONTROLLER_NAME)) {
|
||||||
@@ -90,7 +90,7 @@ class App
|
|||||||
try {
|
try {
|
||||||
// 操作方法开始监听
|
// 操作方法开始监听
|
||||||
$call = [$instance, $action];
|
$call = [$instance, $action];
|
||||||
Hook::listen('action_begin', $call);
|
APP_HOOK && Hook::listen('action_begin', $call);
|
||||||
if (!preg_match('/^[A-Za-z](\w)*$/', $action)) {
|
if (!preg_match('/^[A-Za-z](\w)*$/', $action)) {
|
||||||
// 非法操作
|
// 非法操作
|
||||||
throw new \ReflectionException();
|
throw new \ReflectionException();
|
||||||
@@ -109,7 +109,7 @@ class App
|
|||||||
$data = $method->invoke($instance);
|
$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']);
|
Response::returnData($data, $config['default_return_type'], $config['response_exit']);
|
||||||
} else {
|
} 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);
|
Hook::import(include $path . 'tags' . EXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,16 +242,11 @@ class App
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 监听path_info
|
// 监听path_info
|
||||||
Hook::listen('path_info');
|
APP_HOOK && Hook::listen('path_info');
|
||||||
// 分析PATHINFO信息
|
// 分析PATHINFO信息
|
||||||
if (!isset($_SERVER['PATH_INFO']) && $_SERVER['SCRIPT_NAME'] != $_SERVER['PHP_SELF']) {
|
if (!isset($_SERVER['PATH_INFO']) && $_SERVER['SCRIPT_NAME'] != $_SERVER['PHP_SELF']) {
|
||||||
$types = explode(',', $config['pathinfo_fetch']);
|
foreach ($config['pathinfo_fetch'] as $type) {
|
||||||
foreach ($types as $type) {
|
if (!empty($_SERVER[$type])) {
|
||||||
if (0 === strpos($type, ':')) {
|
|
||||||
// 支持函数判断
|
|
||||||
$_SERVER['PATH_INFO'] = call_user_func(substr($type, 1));
|
|
||||||
break;
|
|
||||||
} elseif (!empty($_SERVER[$type])) {
|
|
||||||
$_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME'])) ?
|
$_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME'])) ?
|
||||||
substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
|
substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
|
||||||
break;
|
break;
|
||||||
@@ -273,7 +268,7 @@ class App
|
|||||||
define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION)));
|
define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION)));
|
||||||
if (__INFO__) {
|
if (__INFO__) {
|
||||||
if ($config['url_deny_suffix'] && preg_match('/\.(' . $config['url_deny_suffix'] . ')$/i', __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'];
|
$depr = $config['pathinfo_depr'];
|
||||||
// 还原劫持后真实pathinfo
|
// 还原劫持后真实pathinfo
|
||||||
@@ -323,7 +318,7 @@ class App
|
|||||||
|
|
||||||
// 模块初始化
|
// 模块初始化
|
||||||
if (MODULE_NAME && !in_array(MODULE_NAME, $config['deny_module_list']) && is_dir(APP_PATH . MODULE_NAME)) {
|
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('MODULE_PATH', APP_PATH . MODULE_NAME . DS);
|
||||||
define('VIEW_PATH', MODULE_PATH . VIEW_LAYER . DS);
|
define('VIEW_PATH', MODULE_PATH . VIEW_LAYER . DS);
|
||||||
|
|
||||||
|
|||||||
@@ -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']);
|
Hook::import(is_array($mode['tags']) ? $mode['tags'] : include $mode['tags']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user