From 814f63390d0c96a376a3771ab2af1383ddfc8981 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 10 Jan 2017 11:21:41 +0100 Subject: [PATCH] [DI] Dont share service when no id provided --- .../DependencyInjection/FrameworkExtensionTest.php | 2 +- .../DependencyInjection/CompleteConfigurationTest.php | 2 +- .../Component/DependencyInjection/ContainerBuilder.php | 10 +++++----- .../Component/HttpKernel/Tests/Bundle/BundleTest.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 9736cf17c323..b9116d39a360 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -587,7 +587,7 @@ private function assertUrlPackage(ContainerBuilder $container, DefinitionDecorat private function assertVersionStrategy(ContainerBuilder $container, Reference $reference, $version, $format) { - $versionStrategy = $container->getDefinition($reference); + $versionStrategy = $container->getDefinition((string) $reference); if (null === $version) { $this->assertEquals('assets.empty_version_strategy', (string) $reference); } else { diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php index 16e5787bdf60..a07b3fc82910 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php @@ -162,7 +162,7 @@ public function testAccess() ); } elseif (3 === $i) { $this->assertEquals('IS_AUTHENTICATED_ANONYMOUSLY', $attributes[0]); - $expression = $container->getDefinition($attributes[1])->getArgument(0); + $expression = $container->getDefinition((string) $attributes[1])->getArgument(0); $this->assertEquals("token.getUsername() matches '/^admin/'", $expression); } } diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 012a8e946e3b..496adb9426fc 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -430,7 +430,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV } if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) { - return $this->get($this->aliasDefinitions[$id], $invalidBehavior); + return $this->get((string) $this->aliasDefinitions[$id], $invalidBehavior); } try { @@ -1099,15 +1099,15 @@ private function callMethod($service, $call) /** * Shares a given service in the container. * - * @param Definition $definition - * @param mixed $service - * @param string $id + * @param Definition $definition + * @param mixed $service + * @param string|null $id * * @throws InactiveScopeException */ private function shareService(Definition $definition, $service, $id) { - if (self::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) { + if (null !== $id && self::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) { if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) { throw new InactiveScopeException($id, $scope); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php index 5faf795f8781..58644336984b 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php @@ -46,7 +46,7 @@ public function testGetContainerExtensionWithInvalidClass() public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices() { $container = new ContainerBuilder(); - $container->register('console.command.Symfony_Component_HttpKernel_Tests_Fixtures_ExtensionPresentBundle_Command_FooCommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand'); + $container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand'); $application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock(); // add() is never called when the found command classes are already registered as services