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

RequestListener.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishRestBundle\EventListener;
8
9 use Symfony\Component\HttpKernel\KernelEvents;
10 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
12 use Symfony\Component\HttpFoundation\Request;
13
19 class RequestListener implements EventSubscriberInterface
20 {
21 const REST_PREFIX_PATTERN = '/^\/api\/[a-zA-Z0-9-_]+\/v\d+(\.\d+)?\//';
22
26 public static function getSubscribedEvents()
27 {
28 return [
29 // 10001 is to ensure that REST requests are tagged before CorsListener is called
30 KernelEvents::REQUEST => ['onKernelRequest', 10001],
31 ];
32 }
33
39 public function onKernelRequest(GetResponseEvent $event)
40 {
41 $isRestRequest = true;
42
43 if (!$this->hasRestPrefix($event->getRequest())) {
44 $isRestRequest = false;
45 }
46
47 $event->getRequest()->attributes->set('is_rest_request', $isRestRequest);
48 }
49
55 protected function hasRestPrefix(Request $request)
56 {
57 return preg_match(self::REST_PREFIX_PATTERN, $request->getPathInfo());
58 }
59 }
eZ\Bundle\EzPublishRestBundle\EventListener\RequestListener
REST request listener.
Definition: RequestListener.php:20
eZ\Bundle\EzPublishRestBundle\EventListener\RequestListener\onKernelRequest
onKernelRequest(GetResponseEvent $event)
If the request is a REST one, sets the is_rest_request request attribute.
Definition: RequestListener.php:39
eZ\Bundle\EzPublishRestBundle\EventListener\RequestListener\REST_PREFIX_PATTERN
const REST_PREFIX_PATTERN
Definition: RequestListener.php:21
eZ\Bundle\EzPublishRestBundle\EventListener\RequestListener\hasRestPrefix
hasRestPrefix(Request $request)
Definition: RequestListener.php:55
eZ\Bundle\EzPublishRestBundle\EventListener\RequestListener\getSubscribedEvents
static getSubscribedEvents()
Definition: RequestListener.php:26
eZ\Bundle\EzPublishRestBundle\EventListener
Definition: CsrfListener.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.