Contao\CoreBundle\EventListener\PrettyErrorScreenListener::onKernelException PHP Метод

onKernelException() публичный Метод

Map an exception to an error screen.
public onKernelException ( GetResponseForExceptionEvent $event )
$event Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        if (!$event->isMasterRequest() || 'html' !== $event->getRequest()->getRequestFormat()) {
            return;
        }
        $this->handleException($event);
    }

Usage Example

 /**
  * Tests rendering the error screen.
  */
 public function testErrorScreen()
 {
     $event = new GetResponseForExceptionEvent($this->mockKernel(), new Request(), HttpKernelInterface::MASTER_REQUEST, new NotFoundHttpException('', new PageNotFoundException()));
     $count = 0;
     $twig = $this->getMock('Twig_Environment', ['render']);
     $twig->expects($this->any())->method('render')->willReturnCallback(function () use(&$count) {
         if (0 === $count++) {
             throw new \Twig_Error('foo');
         }
     });
     $listener = new PrettyErrorScreenListener(true, $twig, new ConfigAdapter());
     $listener->onKernelException($event);
     $this->assertTrue($event->hasResponse());
     $response = $event->getResponse();
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals(500, $response->getStatusCode());
 }
All Usage Examples Of Contao\CoreBundle\EventListener\PrettyErrorScreenListener::onKernelException