src/EventSubscriber/LanguageSubscriber.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. class LanguageSubscriber implements EventSubscriberInterface
  7. {
  8.     public function executingRequest(RequestEvent $event)
  9.     {
  10.         $request $event->getRequest();
  11.         if ($locale $request->attributes->get('_locale'))
  12.         {
  13.             $request->getSession()->set('_locale'$locale);
  14.         } else
  15.         {
  16.             $request->setLocale($request->getSession()->get('_locale'$request->getDefaultLocale()));
  17.         }
  18.     }
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return 
  22.         [
  23.             KernelEvents::REQUEST => [['executingRequest'20]]
  24.         ];
  25.     }    
  26. }