vendor/shopware/core/Framework/Routing/RouteEventSubscriber.php line 57

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