src/Flexy/FrontBundle/Themes/Niiamart/EventListener/KernelListener.php line 39

  1. <?php
  2. namespace App\Flexy\FrontBundle\Themes\Niiamart\EventListener;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  5. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  6. use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
  7. use Symfony\Component\HttpFoundation\RedirectResponse;
  8. use Symfony\Component\HttpKernel\Event\RequestEvent;
  9. #[AsEventListener(eventRequestEvent::class, method'onKernelRequest')]
  10. #[AsEventListener(eventExceptionEvent::class, method'onKernelException')]
  11. class KernelListener
  12. {
  13.     public function onKernelException(ExceptionEvent $event): void
  14.     {
  15.         // You get the exception object from the received event
  16.         
  17.        
  18.         $request $event->getRequest();
  19.         
  20.          
  21.         //$statusCode = $event->getThrowable()->getStatusCode();
  22.         // To check with code later
  23.          
  24.          
  25.         $response = new RedirectResponse('/'.$request->getLocale().'/page-not-found');
  26.         //$event->setResponse($response);
  27.  
  28.     }
  29.         public function onKernelRequest(RequestEvent $event)
  30.     {
  31.         $request $event->getRequest();
  32.         $locale $request->getLocale();
  33.         
  34.         if($request->query->get("_locale")){
  35.             if($request->query->get("_locale") != $locale){
  36.                 $request->setLocale($request->query->get("_locale"));
  37.             }
  38.         }
  39.        
  40.     }
  41. }