From 68b274aa52215ef331b3f64ad4b9d6a5eaeebbe7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 14 Aug 2017 15:40:32 +0800 Subject: [PATCH] =?UTF-8?q?exception=5Fhandle=E9=85=8D=E7=BD=AE=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8=E9=97=AD=E5=8C=85?= =?UTF-8?q?=E5=AE=9A=E4=B9=89render=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Error.php | 3 +++ library/think/exception/Handle.php | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/library/think/Error.php b/library/think/Error.php index c17292bf..42827424 100644 --- a/library/think/Error.php +++ b/library/think/Error.php @@ -110,6 +110,9 @@ class Error $handle = new $class; } else { $handle = new Handle; + if ($class instanceof \Closure) { + $handle->setRender($class); + } } } return $handle; diff --git a/library/think/exception/Handle.php b/library/think/exception/Handle.php index d975690e..f523db09 100644 --- a/library/think/exception/Handle.php +++ b/library/think/exception/Handle.php @@ -21,11 +21,16 @@ use think\Response; class Handle { - + protected $render; protected $ignoreReport = [ '\\think\\exception\\HttpException', ]; + public function setRender($render) + { + $this->render = $render; + } + /** * Report or log an exception. * @@ -78,6 +83,13 @@ class Handle */ 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) { return $this->renderHttpException($e); } else {