local/modules/OpenApi/EventListener/RequestListener.php line 23

  1. <?php
  2. namespace OpenApi\EventListener;
  3. use OpenApi\Controller\Front\BaseFrontOpenApiController;
  4. use OpenApi\OpenApi;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Thelia\Core\Event\TheliaEvents;
  9. use Thelia\Core\Security\SecurityContext;
  10. class RequestListener implements EventSubscriberInterface
  11. {
  12.     protected $securityContext;
  13.     public function __construct(
  14.         SecurityContext $securityContext
  15.     ) {
  16.         $this->securityContext $securityContext;
  17.     }
  18.     public function markRequestAsOpenApi(ControllerEvent $event): void
  19.     {
  20.         $controller $event->getController();
  21.         if (is_array($controller) && isset($controller[0]) && $controller[0] instanceof BaseFrontOpenApiController) {
  22.             $currentRequest $event->getRequest();
  23.             $currentRequest->attributes->set('_previous_url''dont-save');
  24.             $currentRequest->attributes->set(OpenApi::OPEN_API_ROUTE_REQUEST_KEYtrue);
  25.         }
  26.     }
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.             KernelEvents::CONTROLLER => [
  31.                 ['markRequestAsOpenApi'512],
  32.             ],
  33.         ];
  34.     }
  35. }