Last active
December 17, 2015 20:48
-
-
Save wpottier/5670027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Formation\CoreBundle\Listener; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | |
use Symfony\Component\HttpKernel\KernelEvents; | |
class LocaleListener implements EventSubscriberInterface | |
{ | |
public function onKernelRequest(GetResponseEvent $event) | |
{ | |
$request = $event->getRequest(); | |
if(!$request->getSession()->has('locale')) { | |
$request->getSession()->set('locale', $request->getPreferredLanguage()); | |
} | |
$request->setLocale($request->getSession()->get('locale')); | |
} | |
public static function getSubscribedEvents() | |
{ | |
return array(KernelEvents::REQUEST => array(array('onKernelRequest', 17))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment