src/EventSubscriber/ExceptionSubscriber.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Tools\LocaleHelper;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class ExceptionSubscriber implements EventSubscriberInterface
  8. {
  9.     private $localeHelper;
  10.     public function __construct(LocaleHelper $localeHelper)
  11.     {
  12.         $this->localeHelper $localeHelper;
  13.     }
  14.     public function onKernelException(ExceptionEvent $event)
  15.     {
  16.         $request $event->getRequest();
  17.         $locale $this->localeHelper->guessLocaleFromRequest($request);
  18.         if (!empty($locale)) {
  19.             $request->setLocale($locale);
  20.         }
  21.     }
  22.     public static function getSubscribedEvents()
  23.     {
  24.         return [
  25.             KernelEvents::EXCEPTION => [
  26.                 ['onKernelException'60]
  27.             ]
  28.         ];
  29.     }
  30. }