ApiPlatform\Core\EventListener\ExceptionListener::onKernelException PHP Метод

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

public onKernelException ( GetResponseForExceptionEvent $event )
$event Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $request = $event->getRequest();
        // Normalize exceptions only for routes managed by API Platform
        if ('html' === $request->getRequestFormat(null) || !$request->attributes->has('_api_resource_class') && !$request->attributes->has('_api_respond')) {
            return;
        }
        parent::onKernelException($event);
    }

Usage Example

Пример #1
0
 public function testDoNothingWhenHtmlRequested()
 {
     $request = new Request([], [], ['_api_respond' => true]);
     $request->setRequestFormat('html');
     $eventProphecy = $this->prophesize(GetResponseForExceptionEvent::class);
     $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled();
     $listener = new ExceptionListener('foo:bar');
     $listener->onKernelException($eventProphecy->reveal());
 }
ExceptionListener