更新tp5内核

This commit is contained in:
2018-01-02 23:03:31 +08:00
parent 590696a06b
commit 3818619504
99 changed files with 3362 additions and 2006 deletions
+47 -28
View File
@@ -2,7 +2,7 @@
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
@@ -20,6 +20,7 @@ class Error
{
/**
* 注册异常处理
* @access public
* @return void
*/
public static function register()
@@ -31,8 +32,10 @@ class Error
}
/**
* Exception Handler
* @param \Exception|\Throwable $e
* 异常处理
* @access public
* @param \Exception|\Throwable $e 异常
* @return void
*/
public static function appException($e)
{
@@ -40,44 +43,50 @@ class Error
$e = new ThrowableError($e);
}
self::getExceptionHandler()->report($e);
$handler = self::getExceptionHandler();
$handler->report($e);
if (IS_CLI) {
self::getExceptionHandler()->renderForConsole(new ConsoleOutput, $e);
$handler->renderForConsole(new ConsoleOutput, $e);
} else {
self::getExceptionHandler()->render($e)->send();
$handler->render($e)->send();
}
}
/**
* Error Handler
* @param integer $errno 错误编号
* @param integer $errstr 详细错误信息
* @param string $errfile 出错的文件
* @param integer $errline 出错行号
* @param array $errcontext
* 错误处理
* @access public
* @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, $errcontext = [])
public static function appError($errno, $errstr, $errfile = '', $errline = 0)
{
$exception = new ErrorException($errno, $errstr, $errfile, $errline, $errcontext);
$exception = new ErrorException($errno, $errstr, $errfile, $errline);
// 符合异常处理的则将错误信息托管至 think\exception\ErrorException
if (error_reporting() & $errno) {
// 将错误信息托管至 think\exception\ErrorException
throw $exception;
} else {
self::getExceptionHandler()->report($exception);
}
self::getExceptionHandler()->report($exception);
}
/**
* 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']
));
}
// 写入日志
@@ -86,8 +95,8 @@ class Error
/**
* 确定错误类型是否致命
*
* @param int $type
* @access protected
* @param int $type 错误类型
* @return bool
*/
protected static function isFatal($type)
@@ -96,22 +105,32 @@ class Error
}
/**
* Get an instance of the exception handler.
*
* 获取异常处理的实例
* @access public
* @return Handle
*/
public static function getExceptionHandler()
{
static $handle;
if (!$handle) {
// 异常处理handle
// 异常处理 handle
$class = Config::get('exception_handle');
if ($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);
}
}
}
return $handle;
}
}