Newscoop\GimmeBundle\EventListener\ExceptionListener::onKernelException PHP Method

onKernelException() public method

public onKernelException ( GetResponseForExceptionEvent $event )
$event Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        static $handling;
        if (true === $handling) {
            return false;
        }
        $handling = true;
        $exception = $event->getException();
        $request = $event->getRequest();
        $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
        $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, 'format' => $request->getRequestFormat());
        $request = $request->duplicate(null, null, $attributes);
        $request->setMethod($event->getRequest()->getMethod());
        try {
            $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
        } catch (\Exception $e) {
            $this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
            // set handling to false otherwise it wont be able to handle further more
            $handling = false;
            // re-throw the exception from within HttpKernel as this is a catch-all
            return;
        }
        $event->setResponse($response);
        $handling = false;
    }
ExceptionListener