格式化 start、base、traits 和 App、Config、Error、Loader 代码的样式。其他代码的样式待处理。

This commit is contained in:
Lin07ux
2017-11-05 15:21:42 +08:00
committed by ThinkPHP
parent 0fb51680e8
commit 35e763c8ff
9 changed files with 682 additions and 513 deletions

View File

@@ -31,53 +31,55 @@ class Error
}
/**
* Exception Handler
* @param \Exception|\Throwable $e
* 异常处理
* @param \Exception|\Throwable $e 异常
* @return void
*/
public static function appException($e)
{
if (!$e instanceof \Exception) {
$e = new ThrowableError($e);
}
if (!$e instanceof \Exception) $e = new ThrowableError($e);
$handler = self::getExceptionHandler();
$handler->report($e);
self::getExceptionHandler()->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
* 错误处理
* @param integer $errno 错误编号
* @param integer $errstr 详细错误信息
* @param string $errfile 出错的文件
* @param integer $errline 出错行号
* @param array $errcontext 出错上下文
* @return void
* @throws ErrorException
*/
public static function appError($errno, $errstr, $errfile = '', $errline = 0, $errcontext = [])
{
$exception = new ErrorException($errno, $errstr, $errfile, $errline, $errcontext);
if (error_reporting() & $errno) {
// 将错误信息托管至 think\exception\ErrorException
throw $exception;
} else {
self::getExceptionHandler()->report($exception);
}
// 符合异常处理的则将错误信息托管至 think\exception\ErrorException
if (error_reporting() & $errno) throw $exception;
self::getExceptionHandler()->report($exception);
}
/**
* Shutdown Handler
* 异常中止处理
* @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 +88,7 @@ class Error
/**
* 确定错误类型是否致命
*
* @param int $type
* @param int $type
* @return bool
*/
protected static function isFatal($type)
@@ -96,25 +97,28 @@ class Error
}
/**
* Get an instance of the exception handler.
*
* 获取异常处理的实例
* @return Handle
*/
public static function getExceptionHandler()
{
static $handle;
if (!$handle) {
// 异常处理handle
// 异常处理 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);
}
if ($class instanceof \Closure) $handle->setRender($class);
}
}
return $handle;
}
}