src/EventSubscriber/UserLocaleSubscriber.php line 27

Open in your IDE?
  1. <?php 
  2. // src/App/EventSubscriber/UserLocaleSubscriber.php
  3. namespace App\EventSubscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  6. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  7. use Symfony\Component\Security\Http\SecurityEvents;
  8. /**
  9.  * Stores the locale of the user in the session after the
  10.  * login. This can be used by the LocaleSubscriber afterwards.
  11.  */
  12. class UserLocaleSubscriber implements EventSubscriberInterface
  13. {
  14.     private $session;
  15.     public function __construct(SessionInterface $session)
  16.     {
  17.         $this->session $session;
  18.     }
  19.     /**
  20.      * @param InteractiveLoginEvent $event
  21.      */
  22.     public function onInteractiveLogin(InteractiveLoginEvent $event)
  23.     {
  24.         $user $event->getAuthenticationToken()->getUser();
  25.         // if (null !== $user->getLocale()) {
  26.         //     $this->session->set('_locale', $user->getLocale());
  27.         // }
  28.     }
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
  33.         ];
  34.     }
  35. }