3 namespace Wallabag\CoreBundle\EventListener
;
5 use Symfony\Component\HttpKernel\Event\GetResponseEvent
;
6 use Symfony\Component\HttpKernel\KernelEvents
;
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface
;
9 class LocaleListener
implements EventSubscriberInterface
11 private $defaultLocale;
13 public function __construct($defaultLocale = 'en')
15 $this->defaultLocale
= $defaultLocale;
18 public function onKernelRequest(GetResponseEvent
$event)
20 $request = $event->getRequest();
21 if (!$request->hasPreviousSession()) {
25 // try to see if the locale has been set as a _locale routing parameter
26 if ($locale = $request->attributes
->get('_locale')) {
27 $request->getSession()->set('_locale', $locale);
29 // if no explicit locale has been set on this request, use one from the session
30 $request->setLocale($request->getSession()->get('_locale', $this->defaultLocale
));
34 public static function getSubscribedEvents()
37 // must be registered before the default Locale listener
38 KernelEvents
::REQUEST
=> array(array('onKernelRequest', 17)),