mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
取消APP_HOOK常量 默认开启插件机制
This commit is contained in:
3
base.php
3
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_ON') or define('APP_ROUTE_ON', true); // 是否允许路由
|
||||||
defined('APP_ROUTE_MUST') or define('APP_ROUTE_MUST', true); // 是否严格检查路由
|
defined('APP_ROUTE_MUST') or define('APP_ROUTE_MUST', true); // 是否严格检查路由
|
||||||
defined('CLASS_APPEND_SUFFIX') or define('CLASS_APPEND_SUFFIX', false); // 是否追加类名后缀
|
defined('CLASS_APPEND_SUFFIX') or define('CLASS_APPEND_SUFFIX', false); // 是否追加类名后缀
|
||||||
// 应用模式 默认为普通模式
|
defined('APP_MODE') or define('APP_MODE', 'common'); // 应用模式 默认为普通模式
|
||||||
defined('APP_MODE') or define('APP_MODE', function_exists('saeAutoLoader') ? 'sae' : 'common');
|
|
||||||
|
|
||||||
// 环境常量
|
// 环境常量
|
||||||
define('IS_CGI', strpos(PHP_SAPI, 'cgi') === 0 ? 1 : 0);
|
define('IS_CGI', strpos(PHP_SAPI, 'cgi') === 0 ? 1 : 0);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class App
|
|||||||
date_default_timezone_set($config['default_timezone']);
|
date_default_timezone_set($config['default_timezone']);
|
||||||
|
|
||||||
// 监听app_init
|
// 监听app_init
|
||||||
APP_HOOK && Hook::listen('app_init');
|
Hook::listen('app_init');
|
||||||
|
|
||||||
// 开启多语言机制
|
// 开启多语言机制
|
||||||
if ($config['lang_switch_on']) {
|
if ($config['lang_switch_on']) {
|
||||||
@@ -93,7 +93,7 @@ class App
|
|||||||
// 记录路由信息
|
// 记录路由信息
|
||||||
APP_DEBUG && Log::record('[ ROUTE ] ' . var_export($dispatch, true), 'info');
|
APP_DEBUG && Log::record('[ ROUTE ] ' . var_export($dispatch, true), 'info');
|
||||||
// 监听app_begin
|
// 监听app_begin
|
||||||
APP_HOOK && Hook::listen('app_begin', $dispatch);
|
Hook::listen('app_begin', $dispatch);
|
||||||
try {
|
try {
|
||||||
switch ($dispatch['type']) {
|
switch ($dispatch['type']) {
|
||||||
case 'redirect':
|
case 'redirect':
|
||||||
@@ -127,7 +127,7 @@ class App
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 监听app_end
|
// 监听app_end
|
||||||
APP_HOOK && Hook::listen('app_end', $data);
|
Hook::listen('app_end', $data);
|
||||||
|
|
||||||
// 输出数据到客户端
|
// 输出数据到客户端
|
||||||
if ($data instanceof Response) {
|
if ($data instanceof Response) {
|
||||||
@@ -266,7 +266,7 @@ class App
|
|||||||
try {
|
try {
|
||||||
// 操作方法开始监听
|
// 操作方法开始监听
|
||||||
$call = [$instance, $action];
|
$call = [$instance, $action];
|
||||||
APP_HOOK && Hook::listen('action_begin', $call);
|
Hook::listen('action_begin', $call);
|
||||||
if (!preg_match('/^[A-Za-z](\w)*$/', $action)) {
|
if (!preg_match('/^[A-Za-z](\w)*$/', $action)) {
|
||||||
// 非法操作
|
// 非法操作
|
||||||
throw new \ReflectionException('illegal action name :' . ACTION_NAME);
|
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);
|
Hook::import(include $path . 'tags' . EXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class Log
|
|||||||
$log[] = ['type' => $type, 'msg' => $msg];
|
$log[] = ['type' => $type, 'msg' => $msg];
|
||||||
|
|
||||||
// 监听log_write
|
// 监听log_write
|
||||||
APP_HOOK && Hook::listen('log_write', $log);
|
Hook::listen('log_write', $log);
|
||||||
if (is_null(self::$driver)) {
|
if (is_null(self::$driver)) {
|
||||||
self::init(Config::get('log'));
|
self::init(Config::get('log'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class Response
|
|||||||
$data = $this->output($data);
|
$data = $this->output($data);
|
||||||
|
|
||||||
// 监听response_data
|
// 监听response_data
|
||||||
APP_HOOK && Hook::listen('response_data', $data);
|
Hook::listen('response_data', $data);
|
||||||
|
|
||||||
// 发送头部信息
|
// 发送头部信息
|
||||||
if (!headers_sent() && !empty($this->header)) {
|
if (!headers_sent() && !empty($this->header)) {
|
||||||
|
|||||||
@@ -750,7 +750,7 @@ class Route
|
|||||||
// 请求类型检测
|
// 请求类型检测
|
||||||
if ((isset($option['method']) && false === stripos($option['method'], REQUEST_METHOD))
|
if ((isset($option['method']) && false === stripos($option['method'], REQUEST_METHOD))
|
||||||
|| (isset($option['ext']) && false === stripos($option['ext'], __EXT__)) // 伪静态后缀检测
|
|| (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['https']) && !$request->isSsl()) // https检测
|
||||||
|| (!empty($option['before_behavior']) && false === Hook::exec($option['before_behavior'], $url)) // 行为检测
|
|| (!empty($option['before_behavior']) && false === Hook::exec($option['before_behavior'], $url)) // 行为检测
|
||||||
|| (!empty($option['callback']) && is_callable($option['callback']) && false === call_user_func($option['callback'])) // 自定义检测
|
|| (!empty($option['callback']) && is_callable($option['callback']) && false === call_user_func($option['callback'])) // 自定义检测
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class View
|
|||||||
// 获取并清空缓存
|
// 获取并清空缓存
|
||||||
$content = ob_get_clean();
|
$content = ob_get_clean();
|
||||||
// 内容过滤标签
|
// 内容过滤标签
|
||||||
APP_HOOK && Hook::listen('view_filter', $content);
|
Hook::listen('view_filter', $content);
|
||||||
// 允许用户自定义模板的字符串替换
|
// 允许用户自定义模板的字符串替换
|
||||||
$replace = array_merge($this->replace, $replace);
|
$replace = array_merge($this->replace, $replace);
|
||||||
if (!empty($replace)) {
|
if (!empty($replace)) {
|
||||||
|
|||||||
@@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
namespace think\log\driver;
|
namespace think\log\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
use think\Config;
|
use think\Config;
|
||||||
|
use think\Db;
|
||||||
use think\Debug;
|
use think\Debug;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,8 +55,8 @@ class Trace
|
|||||||
$base = [
|
$base = [
|
||||||
'请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
|
'请求信息' => 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()),
|
'运行时间' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 内存消耗:{$mem}kb 文件加载:" . count(get_included_files()),
|
||||||
'查询信息' => \think\Db::$queryTimes . ' queries ' . \think\Db::$executeTimes . ' writes ',
|
'查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ',
|
||||||
'缓存信息' => \think\Cache::$readTimes . ' reads,' . \think\Cache::$writeTimes . ' writes',
|
'缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes',
|
||||||
'配置加载' => count(Config::get()),
|
'配置加载' => count(Config::get()),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
Hook::import(include APP_PATH . 'tags' . EXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +102,6 @@ class App
|
|||||||
date_default_timezone_set($config['default_timezone']);
|
date_default_timezone_set($config['default_timezone']);
|
||||||
|
|
||||||
// 监听app_init
|
// 监听app_init
|
||||||
APP_HOOK && Hook::listen('app_init');
|
Hook::listen('app_init');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,11 +54,8 @@ if (isset($mode['config'])) {
|
|||||||
is_array($mode['config']) ? Config::set($mode['config']) : Config::load($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']);
|
Hook::import($mode['tags']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user