src/Listener/WmApiListener.php line 32

Open in your IDE?
  1. <?php
  2.     namespace App\Listener;
  3.     use App\Services\DTV\YamlConfig\YamlReader;
  4.     use Symfony\Component\HttpFoundation\RedirectResponse;
  5.     use Symfony\Component\HttpKernel\Event\RequestEvent;
  6.     use Symfony\Component\Routing\RouterInterface;
  7.     class WmApiListener
  8.     {
  9.         private RouterInterface $router;
  10.         private YamlReader      $yamlReader;
  11.         public function __construct(
  12.             RouterInterface $router,
  13.             YamlReader      $yamlReader
  14.         )
  15.         {
  16.             $this->router     $router;
  17.             $this->yamlReader $yamlReader;
  18.         }
  19.         /**
  20.          * @param RequestEvent $event
  21.          *
  22.          * @return void
  23.          */
  24.         public function onKernelRequestRequestEvent $event ): void
  25.         {
  26.             $currentRoute $event->getRequest()->get'_route' );
  27.             if ( !in_array(
  28.                 $currentRoute,
  29.                 [
  30.                     'front_common_css_custom',
  31.                     'front_common_document',
  32.                     'front_common_document_html',
  33.                     'front_user_accept_cgu_first',
  34.                     'front_user_accept_cgu_only',
  35.                 ],
  36.                 TRUE )
  37.             ) {
  38.                 if ( $this->yamlReader->getType() === ( 'api' ) ) {
  39.                     if ( preg_match'/^front_(.*)/'$currentRoute ) ) {
  40.                         $url      $this->router->generate'back_dashboard' );
  41.                         $response = new RedirectResponse$url );
  42.                         $event->setResponse$response );
  43.                     }
  44.                 }
  45.             }
  46.         }
  47.     }