src/EventSubscriber/PreRouterSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpKernel\Event\RequestEvent;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Symfony\Component\Routing\RouterInterface;
  9. class PreRouterSubscriber implements EventSubscriberInterface
  10. {
  11.     const specDomain = ["local-blcontacto.groupeall.com""blcontactopp.groupeall.com""blcontacto.groupeall.com"];
  12.     public function __construct(private RouterInterface $router)
  13.     {
  14.     }
  15.     public function onKernelRequest(RequestEvent $event): void
  16.     {
  17.         if (!$event->isMainRequest()) {
  18.             // don't do anything if it's not the main request
  19.             return;
  20.         }
  21.         if (in_array($event->getRequest()->getHttpHost(), self::specDomain)) {
  22.             $params explode('/'substr($event->getRequest()->getPathInfo(), 1));
  23.             if (count($params) == ) {
  24.                 $redirect $this->router->generate("view_bl", ['token' => $params[0], 'num' => $params[1], 'code' => $params[2]]);
  25.                 $event->setResponse(new RedirectResponse($redirect));
  26.             }
  27.         }
  28.     }
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [KernelEvents::REQUEST => ['onKernelRequest'33]];
  32.     }
  33. }