From da156d3f944aaf7ef483dca415f259a3113a0b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Ja=CC=88ger?= Date: Tue, 16 Apr 2013 21:35:51 +0200 Subject: [PATCH 1/2] fix overwriting of request's locale if attribute _locale is missing --- .../HttpKernel/EventListener/LocaleListener.php | 2 +- .../Tests/EventListener/LocaleListenerTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php index f3cb804832..dac810abae 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php @@ -50,7 +50,7 @@ class LocaleListener implements EventSubscriberInterface $request = $event->getRequest(); $request->setDefaultLocale($this->defaultLocale); - $this->setLocale($request, $request->attributes->get('_locale', $this->defaultLocale)); + $this->setLocale($request, $request->attributes->get('_locale', $request->getLocale())); array_unshift($this->locales, $request->getLocale()); } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php index 9ca64321b2..e5e4e3a286 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php @@ -68,6 +68,17 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase $listener->onKernelRequest($this->getEvent($request)); } + public function testRequestLocaleIsNotOverridden() + { + $request = Request::create('/'); + $request->setLocale('de'); + $listener = new LocaleListener('fr'); + $event = $this->getEvent($request); + + $listener->onKernelRequest($event); + $this->assertEquals('de', $request->getLocale()); + } + private function getEvent(Request $request) { return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST); From 22bf96561e1fe103d32f381e41ff5722588fc5b9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 17 Apr 2013 13:23:58 +0200 Subject: [PATCH 2/2] [DependencyInjection] fixed wrong exception class --- src/Symfony/Component/DependencyInjection/ContainerBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 71379ef1e8..a43e08c7fe 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\Compiler\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\Exception\BadMethodCallException; +use Symfony\Component\DependencyInjection\Exception\InactiveScopeException; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; @@ -774,7 +775,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface if (self::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) { if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) { - throw new RuntimeException('You tried to create a service of an inactive scope.'); + throw new InactiveScopeException($id, $scope); } $this->services[$lowerId = strtolower($id)] = $service;