]>
Commit | Line | Data |
---|---|---|
c89d35e8 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\EventListener; | |
4 | ||
5 | use Symfony\Component\HttpFoundation\Session\Session; | |
6 | use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | |
7 | ||
8 | /** | |
9 | * Stores the locale of the user in the session after the | |
10 | * login. This can be used by the LocaleListener afterwards. | |
2aac2f27 JB |
11 | * |
12 | * @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html | |
c89d35e8 NL |
13 | */ |
14 | class UserLocaleListener | |
15 | { | |
16 | /** | |
17 | * @var Session | |
18 | */ | |
19 | private $session; | |
20 | ||
21 | public function __construct(Session $session) | |
22 | { | |
23 | $this->session = $session; | |
24 | } | |
25 | ||
26 | /** | |
27 | * @param InteractiveLoginEvent $event | |
28 | */ | |
29 | public function onInteractiveLogin(InteractiveLoginEvent $event) | |
30 | { | |
31 | $user = $event->getAuthenticationToken()->getUser(); | |
32 | ||
33 | if (null !== $user->getConfig()->getLanguage()) { | |
34 | $this->session->set('_locale', $user->getConfig()->getLanguage()); | |
35 | } | |
36 | } | |
37 | } |