<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\RouterInterface;
class PreRouterSubscriber implements EventSubscriberInterface
{
const specDomain = ["local-blcontacto.groupeall.com", "blcontactopp.groupeall.com", "blcontacto.groupeall.com"];
public function __construct(private RouterInterface $router)
{
}
public function onKernelRequest(RequestEvent $event): void
{
if (!$event->isMainRequest()) {
// don't do anything if it's not the main request
return;
}
if (in_array($event->getRequest()->getHttpHost(), self::specDomain)) {
$params = explode('/', substr($event->getRequest()->getPathInfo(), 1));
if (count($params) == 3 ) {
$redirect = $this->router->generate("view_bl", ['token' => $params[0], 'num' => $params[1], 'code' => $params[2]]);
$event->setResponse(new RedirectResponse($redirect));
}
}
}
public static function getSubscribedEvents(): array
{
return [KernelEvents::REQUEST => ['onKernelRequest', 33]];
}
}