feat: 本次提交更新内容如下
php有问题,覆盖下
This commit is contained in:
@@ -18,6 +18,12 @@ use think\exception\ThrowableError;
|
||||
|
||||
class Error
|
||||
{
|
||||
/**
|
||||
* 配置参数
|
||||
* @var array
|
||||
*/
|
||||
protected static $exceptionHandler;
|
||||
|
||||
/**
|
||||
* 注册异常处理
|
||||
* @access public
|
||||
@@ -32,10 +38,9 @@ class Error
|
||||
}
|
||||
|
||||
/**
|
||||
* 异常处理
|
||||
* Exception Handler
|
||||
* @access public
|
||||
* @param \Exception|\Throwable $e 异常
|
||||
* @return void
|
||||
* @param \Exception|\Throwable $e
|
||||
*/
|
||||
public static function appException($e)
|
||||
{
|
||||
@@ -43,32 +48,29 @@ class Error
|
||||
$e = new ThrowableError($e);
|
||||
}
|
||||
|
||||
$handler = self::getExceptionHandler();
|
||||
$handler->report($e);
|
||||
self::getExceptionHandler()->report($e);
|
||||
|
||||
if (IS_CLI) {
|
||||
$handler->renderForConsole(new ConsoleOutput, $e);
|
||||
if (PHP_SAPI == 'cli') {
|
||||
self::getExceptionHandler()->renderForConsole(new ConsoleOutput, $e);
|
||||
} else {
|
||||
$handler->render($e)->send();
|
||||
self::getExceptionHandler()->render($e)->send();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误处理
|
||||
* Error Handler
|
||||
* @access public
|
||||
* @param integer $errno 错误编号
|
||||
* @param integer $errstr 详细错误信息
|
||||
* @param string $errfile 出错的文件
|
||||
* @param integer $errline 出错行号
|
||||
* @return void
|
||||
* @param integer $errno 错误编号
|
||||
* @param integer $errstr 详细错误信息
|
||||
* @param string $errfile 出错的文件
|
||||
* @param integer $errline 出错行号
|
||||
* @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;
|
||||
}
|
||||
|
||||
@@ -76,27 +78,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'])) {
|
||||
self::appException(new ErrorException(
|
||||
$error['type'], $error['message'], $error['file'], $error['line']
|
||||
));
|
||||
// 将错误信息托管至think\ErrorException
|
||||
$exception = new ErrorException($error['type'], $error['message'], $error['file'], $error['line']);
|
||||
|
||||
self::appException($exception);
|
||||
}
|
||||
|
||||
// 写入日志
|
||||
Log::save();
|
||||
Container::get('log')->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 确定错误类型是否致命
|
||||
*
|
||||
* @access protected
|
||||
* @param int $type 错误类型
|
||||
* @param int $type
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isFatal($type)
|
||||
@@ -105,7 +107,20 @@ 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
|
||||
*/
|
||||
@@ -114,20 +129,16 @@ class Error
|
||||
static $handle;
|
||||
|
||||
if (!$handle) {
|
||||
// 异常处理 handle
|
||||
$class = Config::get('exception_handle');
|
||||
// 异常处理handle
|
||||
$class = self::$exceptionHandler;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user