exception_handle配置参数支持使用闭包定义render处理

This commit is contained in:
thinkphp
2017-08-14 15:40:32 +08:00
parent fdb5a966ed
commit 68b274aa52
2 changed files with 16 additions and 1 deletions

View File

@@ -110,6 +110,9 @@ class Error
$handle = new $class; $handle = new $class;
} else { } else {
$handle = new Handle; $handle = new Handle;
if ($class instanceof \Closure) {
$handle->setRender($class);
}
} }
} }
return $handle; return $handle;

View File

@@ -21,11 +21,16 @@ use think\Response;
class Handle class Handle
{ {
protected $render;
protected $ignoreReport = [ protected $ignoreReport = [
'\\think\\exception\\HttpException', '\\think\\exception\\HttpException',
]; ];
public function setRender($render)
{
$this->render = $render;
}
/** /**
* Report or log an exception. * Report or log an exception.
* *
@@ -78,6 +83,13 @@ class Handle
*/ */
public function render(Exception $e) public function render(Exception $e)
{ {
if ($this->render && $this->render instanceof \Closure) {
$result = call_user_func_array($this->render, [$e]);
if ($result) {
return $result;
}
}
if ($e instanceof HttpException) { if ($e instanceof HttpException) {
return $this->renderHttpException($e); return $this->renderHttpException($e);
} else { } else {