feat: 同步下新环境

This commit is contained in:
笔记本里的永平
2025-07-07 11:31:25 +08:00
parent 3d1050db3d
commit 86c261ba70
196 changed files with 13146 additions and 29319 deletions

View File

@@ -18,12 +18,6 @@ use think\exception\ThrowableError;
class Error
{
/**
* 配置参数
* @var array
*/
protected static $exceptionHandler;
/**
* 注册异常处理
* @access public
@@ -38,9 +32,10 @@ class Error
}
/**
* Exception Handler
* 异常处理
* @access public
* @param \Exception|\Throwable $e
* @param \Exception|\Throwable $e 异常
* @return void
*/
public static function appException($e)
{
@@ -48,29 +43,32 @@ class Error
$e = new ThrowableError($e);
}
self::getExceptionHandler()->report($e);
$handler = self::getExceptionHandler();
$handler->report($e);
if (PHP_SAPI == 'cli') {
self::getExceptionHandler()->renderForConsole(new ConsoleOutput, $e);
if (IS_CLI) {
$handler->renderForConsole(new ConsoleOutput, $e);
} else {
self::getExceptionHandler()->render($e)->send();
$handler->render($e)->send();
}
}
/**
* Error Handler
* 错误处理
* @access public
* @param integer $errno 错误编号
* @param integer $errstr 详细错误信息
* @param string $errfile 出错的文件
* @param integer $errline 出错行号
* @param integer $errno 错误编号
* @param integer $errstr 详细错误信息
* @param string $errfile 出错的文件
* @param integer $errline 出错行号
* @return void
* @throws ErrorException
*/
public static function appError($errno, $errstr, $errfile = '', $errline = 0)
{
$exception = new ErrorException($errno, $errstr, $errfile, $errline);
// 符合异常处理的则将错误信息托管至 think\exception\ErrorException
if (error_reporting() & $errno) {
// 将错误信息托管至 think\exception\ErrorException
throw $exception;
}
@@ -78,27 +76,27 @@ class Error
}
/**
* Shutdown Handler
* 异常中止处理
* @access public
* @return void
*/
public static function appShutdown()
{
// 将错误信息托管至 think\ErrorException
if (!is_null($error = error_get_last()) && self::isFatal($error['type'])) {
// 将错误信息托管至think\ErrorException
$exception = new ErrorException($error['type'], $error['message'], $error['file'], $error['line']);
self::appException($exception);
self::appException(new ErrorException(
$error['type'], $error['message'], $error['file'], $error['line']
));
}
// 写入日志
Container::get('log')->save();
Log::save();
}
/**
* 确定错误类型是否致命
*
* @access protected
* @param int $type
* @param int $type 错误类型
* @return bool
*/
protected static function isFatal($type)
@@ -107,20 +105,7 @@ class Error
}
/**
* 设置异常处理
*
* @access public
* @param mixed $handle
* @return void
*/
public static function setExceptionHandler($handle)
{
self::$exceptionHandler = $handle;
}
/**
* Get an instance of the exception handler.
*
* 获取异常处理的实例
* @access public
* @return Handle
*/
@@ -129,16 +114,20 @@ class Error
static $handle;
if (!$handle) {
// 异常处理handle
$class = self::$exceptionHandler;
// 异常处理 handle
$class = Config::get('exception_handle');
if ($class && is_string($class) && class_exists($class) && is_subclass_of($class, "\\think\\exception\\Handle")) {
if ($class && is_string($class) && class_exists($class) &&
is_subclass_of($class, "\\think\\exception\\Handle")
) {
$handle = new $class;
} else {
$handle = new Handle;
if ($class instanceof \Closure) {
$handle->setRender($class);
}
}
}