Commit 9e9b3548 by Qiang Xue

refactor Exception::toArrayRecursive().

parent a4a15963
...@@ -39,21 +39,12 @@ class Exception extends \Exception implements Arrayable ...@@ -39,21 +39,12 @@ class Exception extends \Exception implements Arrayable
*/ */
protected function toArrayRecursive($exception) protected function toArrayRecursive($exception)
{ {
if ($exception instanceof self) { $array = array(
$array = array( 'type' => get_class($exception),
'type' => get_class($exception), 'name' => $exception instanceof self ? $exception->getName() : 'Exception',
'name' => $exception->getName(), 'message' => $exception->getMessage(),
'message' => $exception->getMessage(), 'code' => $exception->getCode(),
'code' => $exception->getCode(), );
);
} else {
$array = array(
'type' => get_class($exception),
'name' => 'Exception',
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
);
}
if (($prev = $exception->getPrevious()) !== null) { if (($prev = $exception->getPrevious()) !== null) {
$array['previous'] = $this->toArrayRecursive($prev); $array['previous'] = $this->toArrayRecursive($prev);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment