Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

ResponseListener.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishRestBundle\EventListener;
8
9 use eZ\Publish\Core\REST\Server\View\AcceptHeaderVisitorDispatcher;
10 use Symfony\Component\HttpKernel\KernelEvents;
11 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12 use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
13 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
14
20 class ResponseListener implements EventSubscriberInterface
21 {
23 private $viewDispatcher;
24
28 public function __construct(AcceptHeaderVisitorDispatcher $viewDispatcher)
29 {
30 $this->viewDispatcher = $viewDispatcher;
31 }
32
36 public static function getSubscribedEvents()
37 {
38 return [
39 KernelEvents::VIEW => 'onKernelResultView',
40 // Must happen BEFORE the Core ExceptionListener.
41 KernelEvents::EXCEPTION => ['onKernelExceptionView', 20],
42 ];
43 }
44
48 public function onKernelResultView(GetResponseForControllerResultEvent $event)
49 {
50 if (!$event->getRequest()->attributes->get('is_rest_request')) {
51 return;
52 }
53
54 $event->setResponse(
55 $this->viewDispatcher->dispatch(
56 $event->getRequest(),
57 $event->getControllerResult()
58 )
59 );
60 $event->stopPropagation();
61 }
62
68 public function onKernelExceptionView(GetResponseForExceptionEvent $event)
69 {
70 if (!$event->getRequest()->attributes->get('is_rest_request')) {
71 return;
72 }
73
74 $event->setResponse(
75 $this->viewDispatcher->dispatch(
76 $event->getRequest(),
77 $event->getException()
78 )
79 );
80 $event->stopPropagation();
81 }
82 }
eZ\Bundle\EzPublishRestBundle\EventListener\ResponseListener
REST Response Listener.
Definition: ResponseListener.php:21
eZ\Bundle\EzPublishRestBundle\EventListener\ResponseListener\$viewDispatcher
$viewDispatcher
Definition: ResponseListener.php:23
eZ\Bundle\EzPublishRestBundle\EventListener\ResponseListener\onKernelExceptionView
onKernelExceptionView(GetResponseForExceptionEvent $event)
Definition: ResponseListener.php:68
eZ\Bundle\EzPublishRestBundle\EventListener\ResponseListener\getSubscribedEvents
static getSubscribedEvents()
Definition: ResponseListener.php:36
eZ\Bundle\EzPublishRestBundle\EventListener\ResponseListener\__construct
__construct(AcceptHeaderVisitorDispatcher $viewDispatcher)
Definition: ResponseListener.php:28
eZ\Bundle\EzPublishRestBundle\EventListener\ResponseListener\onKernelResultView
onKernelResultView(GetResponseForControllerResultEvent $event)
Definition: ResponseListener.php:48
eZ\Publish\Core\REST\Server\View\AcceptHeaderVisitorDispatcher
Dispatcher for various visitors depending on the mime-type accept header.
Definition: AcceptHeaderVisitorDispatcher.php:18
eZ\Bundle\EzPublishRestBundle\EventListener
Definition: CsrfListener.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.