* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpKernel\EventListener; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RequestContextAwareInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Initializes the locale based on the current request. * * @author Fabien Potencier */ class LocaleListener implements EventSubscriberInterface { private $router; private $defaultLocale; private $requestStack; /** * @param RequestStack $requestStack A RequestStack instance * @param string $defaultLocale The default locale * @param RequestContextAwareInterface|null $router The router */ public function __construct(RequestStack $requestStack, $defaultLocale = 'en', RequestContextAwareInterface $router = null) { $this->defaultLocale = $defaultLocale; $this->requestStack = $requestStack; $this->router = $router; } public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); $request->setDefaultLocale($this->defaultLocale); $this->setLocale($request); $this->setRouterContext($request); } public function onKernelFinishRequest(FinishRequestEvent $event) { if (null !== $parentRequest = $this->requestStack->getParentRequest()) { $this->setRouterContext($parentRequest); } } private function setLocale(Request $request) { if ($locale = $request->attributes->get('_locale')) { $request->setLocale($locale); } } private function setRouterContext(Request $request) { if (null !== $this->router) { $this->router->getContext()->setParameter('_locale', $request->getLocale()); } } public static function getSubscribedEvents() { return array( // must be registered after the Router to have access to the _locale KernelEvents::REQUEST => array(array('onKernelRequest', 16)), KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)), ); } } __halt_compiler();----SIGNATURE:----oJrynGWLxWsgFwGfhXVTXoapcC320KtwQ364f6F/9waFIB+jHCgDSXHTVWLiAlXj03EduIZSRcaeIiQNB+FNPbu9Bhw1UubAeKpStCTTOq5qrDVSeZ6U7cUMajKUb9sNSwcl17XITLtp3Ey50evoAvgBaz5fu7w5MauQc9zhn47e4ZQZhaZdbzB3mf1UmXiKhzJU2bobTGxhlRZ7bXYbQIXEkA4b2kmHtx7im/QtkEy4WFlh6MjIMhLo3gcTtjwtpDCFPjEAP7QzXc/Y9tuLrPH7u+M6bLwUYSUeYDl9oEnyXtXyTCLPsPArTG0fBpJ7rzi8zPbOulE/5b3MipU80u+qfrDVNbYmXa2yGnWQR5wTO3ymEae4PzLqnIW9vhD3N6jeAyQKxKTfRtnZQMdneoXPkhbmM/3Oqipn6V5Iei0ofWY52rg9qeFM1QF8Roa6zW9LWTvajLICo+I5oK4NehwjDANG2B+QnQRn9plGHwoXmUU4nfXERATfwp1jSHZUkPrZviJkuV3hM2IGWlIXEnm12R9nAzmkU5rSqW0n/NngbQBIQgDu4psFalSc6JinJaNZOFemjnLUuQnofPAV1AS7yPryZtU7/x5E9I7GNTDp42f2nPfsn+XIiJK8eQOphYjyy8yyL7hhNPAmWdybyFbzwSc6dKUltVckTmCrsys=----ATTACHMENT:----MjM1OTk1MjI5MTExMjk3OSA5MDk4MDM3NTU4OTA2MTkxIDcxNzEyODI0MDM0NjYzNDQ=