aboutsummaryrefslogblamecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php
blob: 97bfabc825e45b4952867a288aca41747d6db070 (plain) (tree)


































                                                                              
<?php

namespace Wallabag\CoreBundle\EventListener;

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.
 */
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());
        }
    }
}