src/EventSubscriber/LocaleSubscriber.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. class LocaleSubscriber implements EventSubscriberInterface
  6. {
  7.     public function onKernelRequest(RequestEvent $event): void
  8.     {
  9.         $request $event->getRequest();
  10.         if (!$request->hasPreviousSession()) {
  11.             return;
  12.         }
  13.         if ($locale $request->getSession()->get('_locale')) {
  14.             $request->setLocale($locale);
  15.         }
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             'kernel.request' => [['onKernelRequest'20]],
  21.         ];
  22.     }
  23. }