src/Core/Framework/Routing/RouteEventSubscriber.php line 51

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Routing;
  3. use Shopware\Core\Framework\Log\Package;
  4. use Shopware\Storefront\Event\StorefrontRenderEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  10. /**
  11.  * @internal
  12.  */
  13. #[Package('core')]
  14. class RouteEventSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @internal
  18.      */
  19.     public function __construct(private readonly EventDispatcherInterface $dispatcher)
  20.     {
  21.     }
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         $events = [
  25.             KernelEvents::REQUEST => ['request', -10],
  26.             KernelEvents::RESPONSE => ['response', -10],
  27.         ];
  28.         if (class_exists(StorefrontRenderEvent::class)) {
  29.             $events[StorefrontRenderEvent::class] = ['render', -10];
  30.         }
  31.         return $events;
  32.     }
  33.     public function request(RequestEvent $event): void
  34.     {
  35.         $request $event->getRequest();
  36.         if (!$request->attributes->has('_route')) {
  37.             return;
  38.         }
  39.         $name $request->attributes->get('_route') . '.request';
  40.         $this->dispatcher->dispatch($event$name);
  41.     }
  42.     public function render(StorefrontRenderEvent $event): void
  43.     {
  44.         $request $event->getRequest();
  45.         if (!$request->attributes->has('_route')) {
  46.             return;
  47.         }
  48.         $name $request->attributes->get('_route') . '.render';
  49.         $this->dispatcher->dispatch($event$name);
  50.     }
  51.     public function response(ResponseEvent $event): void
  52.     {
  53.         $request $event->getRequest();
  54.         if (!$request->attributes->has('_route')) {
  55.             return;
  56.         }
  57.         $name $request->attributes->get('_route') . '.response';
  58.         $this->dispatcher->dispatch($event$name);
  59.     }
  60. }