aboutsummaryrefslogblamecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php
blob: 367cdfb00b46be2f49c928d2c94a8ce49ee8a01c (plain) (tree)
1
2
3
4
5
6
7
8
9
10

     
                                             






                                                                

                                                                                 
























                                                                              
<?php

namespace Wallabag\CoreBundle\Event\Listener;

use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;

/**
 * Stores the locale of the user in the session after the
 * login. This can be used by the LocaleListener afterwards.
 *
 * @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html
 */
class UserLocaleListener
{
    /**
     * @var Session
     */
    private $session;

    public function __construct(Session $session)
    {
        $this->session = $session;
    }

    /**
     * @param InteractiveLoginEvent $event
     */
    public function onInteractiveLogin(InteractiveLoginEvent $event)
    {
        $user = $event->getAuthenticationToken()->getUser();

        if (null !== $user->getConfig()->getLanguage()) {
            $this->session->set('_locale', $user->getConfig()->getLanguage());
        }
    }
}