* * 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:----cqAHdHf3qYBFUrV29GqpC3ZDMHaZ1MW3kvhzv4RdqqhC5kUuIkjfYhKRF4fc04YNOI49D60B/cvRf5LqunuZ6cKsui6X6OzqIvrk1NOzoqh/6L47/o57S4nITIPlBU4LQLpxGMH/5l7c1foWbSvwlfBEEZcBsoqQUWuea9iO2QuGunixKu1lK7yoWptPIJeka1pfDBE8zfFcDdMiiIiHFwSDhgFLirhQpXeimN46laIwR02qXiypwS9X+QMNgQ10n2IAvm9aq+pf1mrqvrnFwzqTNhrsRenZjzrIpPLZbnILTr/ayyLaXipC8/zUuw3alJPHd2s0D9pPNxDm1z7qqia8hvtXtSlPp/qlV8lYxNcEJp9ShTXTlcoB1FZfVbwGER3u26RqZsF5SIiJtp8797Fkwg86dOOcH9tanAaJXjtUptknMVlKIDjn+mgCJtMi7ZefxVWat4PUg+R+DyHEcJowtdwVMLknI49oVqMSecNDlezZDFKDhyjFJIVJ31tH+qAf5MRkAAGRv1XDW3dH9V7UPPhSpsACInHDRDsr4zI1w5J4ONcd1es02mfZ8QmgM+zUWf+vGUY4n2wg2sfDhRq3G2CntZfJb3rSA4bUgN5OnC5r9aJR7Jf1kILCQ1Iv58NWUaPhZ1fDwYnXH43LghYzsdrvWM1MLOdD+mvnPWg=----ATTACHMENT:----OTU0MDExNDgzODExNzM1MCAxMzc1NTg5OTI4OTgxMTQyIDkwNjI4NTg2ODAzMzE0NjY=