* * 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\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; 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\Translation\TranslatorInterface; /** * Synchronizes the locale between the request and the translator. * * @author Fabien Potencier */ class TranslatorListener implements EventSubscriberInterface { private $translator; private $requestStack; public function __construct(TranslatorInterface $translator, RequestStack $requestStack) { $this->translator = $translator; $this->requestStack = $requestStack; } public function onKernelRequest(GetResponseEvent $event) { $this->setLocale($event->getRequest()); } public function onKernelFinishRequest(FinishRequestEvent $event) { if (null === $parentRequest = $this->requestStack->getParentRequest()) { return; } $this->setLocale($parentRequest); } public static function getSubscribedEvents() { return array( // must be registered after the Locale listener KernelEvents::REQUEST => array(array('onKernelRequest', 10)), KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)), ); } private function setLocale(Request $request) { try { $this->translator->setLocale($request->getLocale()); } catch (\InvalidArgumentException $e) { $this->translator->setLocale($request->getDefaultLocale()); } } } __halt_compiler();----SIGNATURE:----O5ma5z8pb+SlBLkbQQwZUe2CnAK+qD+iq3Etq1RP6XwCukS4uTfIOEZciVQrMfjrPg/E+4C45ltDrwlWlMq+ibjlh0ti4wAeIzMFZQyhaHgXH+4hMuPTwP3ycYbdJ2BZuncco1J6caK/JLx9WNSEeMoLEJiFHII0ntqyIYN/ztMnzvnbw1rtgFUm24KGaHy4xoyiVUt6LLxwxYlrieew8KZfVFFRgejy1VTqvUExuDGLqoGG41jXbLl+u6XCchHo2Md1l7AN6xeftWUyzO2xpCTHALKyhueZW5x98SbjNh3EJZxyuiN8LbcHPb8FzGCcgV/toCTF/kcadmvqgilAiEnTdN+PmNJj06MqK+1TZlaCPiCs4UCsMMeMLlagzexILOwFPaQ8EEUhds0ZsFn8LzRRledrueOUsIhG6c7/hSyZi/L0omnecL31a+MBT+SEp/nYocsQWq+xPZLyofLPyl2natG3mAV22FNR9gl1HUqDDHh0gjJLgOKUG6bOGYl3CgZw/f5iE/4N9eI+ahzEknhfSWSnt+38T17cO2Qy/NcRxgPjyLXukHj548MtteiXmE9/MHl9pz7y1zNdWy4lFwPWO0P/iqZ7n88nsvW7WF4fvtPArzBsLVNxSLLWYTx5QE+L119hcedLXnQIxzJ4R0oZrQWcZqjlUmwiDnd0RT0=----ATTACHMENT:----MjY0MDQyMTA5NDI2ODMxNSAzMjE2NTMzMTI4MDk0NTY3IDMzNDc4Nzc2OTQ1MzgxMTQ=