Created
December 12, 2011 15:02
-
-
Save kkasprzak/1467691 to your computer and use it in GitHub Desktop.
Locale switch for symfony2
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
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Symfony\Component\HttpKernel\HttpKernelInterface; | |
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | |
class LocaleListener | |
{ | |
private $container; | |
private $defaultLocale; | |
public function __construct(ContainerInterface $container, $defaultLocale = 'nl') | |
{ | |
$this->container = $container; | |
$this->defaultLocale = $defaultLocale; | |
} | |
public function onKernelRequest(GetResponseEvent $event) | |
{ | |
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { | |
return; | |
} | |
if (!$this->container->has('session')) { | |
return; | |
} | |
$session = $this->container->get('session'); | |
$session->setLocale($this->defaultLocale); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment