Commit deb42381 authored by Fabien Potencier's avatar Fabien Potencier

refactored the exception wrapper to make the code easier to understand

parent e54627f6
......@@ -42,6 +42,19 @@ class ExceptionListenerWrapper
{
$exception = $event->getException();
if (!$this->shouldRun($exception)) {
return;
}
$code = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$response = call_user_func($this->callback, $exception, $code);
$this->ensureResponse($response, $event);
}
protected function shouldRun(\Exception $exception)
{
if (is_array($this->callback)) {
$callbackReflection = new \ReflectionMethod($this->callback[0], $this->callback[1]);
} elseif (is_object($this->callback) && !$this->callback instanceof \Closure) {
......@@ -55,14 +68,15 @@ class ExceptionListenerWrapper
$parameters = $callbackReflection->getParameters();
$expectedException = $parameters[0];
if ($expectedException->getClass() && !$expectedException->getClass()->isInstance($exception)) {
return;
return false;
}
}
$code = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$response = call_user_func($this->callback, $exception, $code);
return true;
}
protected function ensureResponse($response, GetResponseForExceptionEvent $event)
{
if ($response instanceof Response) {
$event->setResponse($response);
} else {
......
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