src/Flexy/FrontBundle/Themes/Niiamart/EventListener/KernelListener.php line 39
<?php
namespace App\Flexy\FrontBundle\Themes\Niiamart\EventListener;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\RequestEvent;
#[AsEventListener(event: RequestEvent::class, method: 'onKernelRequest')]
#[AsEventListener(event: ExceptionEvent::class, method: 'onKernelException')]
class KernelListener
{
public function onKernelException(ExceptionEvent $event): void
{
// You get the exception object from the received event
$request = $event->getRequest();
//$statusCode = $event->getThrowable()->getStatusCode();
// To check with code later
$response = new RedirectResponse('/'.$request->getLocale().'/page-not-found');
//$event->setResponse($response);
}
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
$locale = $request->getLocale();
if($request->query->get("_locale")){
if($request->query->get("_locale") != $locale){
$request->setLocale($request->query->get("_locale"));
}
}
}
}