diff --git a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php index 18452d419fa4..bf14ba2d1758 100644 --- a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php +++ b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php @@ -41,14 +41,11 @@ public function process(ContainerBuilder $container) $lazyCommandMap = array(); $lazyCommandRefs = array(); $serviceIds = array(); - $lazyServiceIds = array(); foreach ($commandServices as $id => $tags) { $definition = $container->getDefinition($id); $class = $container->getParameterBag()->resolveValue($definition->getClass()); - $commandId = 'console.command.'.strtolower(str_replace('\\', '_', $class)); - if (isset($tags[0]['command'])) { $commandName = $tags[0]['command']; } else { @@ -62,20 +59,16 @@ public function process(ContainerBuilder $container) } if (null === $commandName) { - if (isset($serviceIds[$commandId]) || $container->hasAlias($commandId)) { - $commandId = $commandId.'_'.$id; - } if (!$definition->isPublic() || $definition->isPrivate()) { + $commandId = 'console.command.public_alias.'.$id; $container->setAlias($commandId, $id)->setPublic(true); $id = $commandId; } - $serviceIds[$commandId] = $id; + $serviceIds[] = $id; continue; } - $serviceIds[$commandId] = $id; - $lazyServiceIds[$id] = true; unset($tags[0]); $lazyCommandMap[$commandName] = $id; $lazyCommandRefs[$id] = new TypedReference($id, $class); @@ -101,6 +94,5 @@ public function process(ContainerBuilder $container) ->setArguments(array(ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap)); $container->setParameter('console.command.ids', $serviceIds); - $container->setParameter('console.lazy_command.ids', $lazyServiceIds); } } diff --git a/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php b/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php index 34f648610836..2a0136d7974c 100644 --- a/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php +++ b/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php @@ -31,28 +31,27 @@ public function testProcess($public) $container->addCompilerPass(new AddConsoleCommandPass()); $container->setParameter('my-command.class', 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand'); + $id = 'my-command'; $definition = new Definition('%my-command.class%'); $definition->setPublic($public); $definition->addTag('console.command'); - $container->setDefinition('my-command', $definition); + $container->setDefinition($id, $definition); $container->compile(); - $alias = 'console.command.symfony_component_console_tests_dependencyinjection_mycommand'; + $alias = 'console.command.public_alias.my-command'; if ($public) { $this->assertFalse($container->hasAlias($alias)); - $id = 'my-command'; } else { - $id = $alias; // The alias is replaced by a Definition by the ReplaceAliasByActualDefinitionPass // in case the original service is private - $this->assertFalse($container->hasDefinition('my-command')); + $this->assertFalse($container->hasDefinition($id)); $this->assertTrue($container->hasDefinition($alias)); } $this->assertTrue($container->hasParameter('console.command.ids')); - $this->assertSame(array($alias => $id), $container->getParameter('console.command.ids')); + $this->assertSame(array($public ? $id : $alias), $container->getParameter('console.command.ids')); } public function testProcessRegistersLazyCommands() @@ -73,8 +72,7 @@ public function testProcessRegistersLazyCommands() $this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass()); $this->assertSame(array('my:command' => 'my-command', 'my:alias' => 'my-command'), $commandLoader->getArgument(1)); $this->assertEquals(array(array('my-command' => new ServiceClosureArgument(new TypedReference('my-command', MyCommand::class)))), $commandLocator->getArguments()); - $this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_mycommand' => 'my-command'), $container->getParameter('console.command.ids')); - $this->assertSame(array('my-command' => true), $container->getParameter('console.lazy_command.ids')); + $this->assertSame(array(), $container->getParameter('console.command.ids')); $this->assertSame(array(array('setName', array('my:command')), array('setAliases', array(array('my:alias')))), $command->getMethodCalls()); } @@ -96,8 +94,7 @@ public function testProcessFallsBackToDefaultName() $this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass()); $this->assertSame(array('default' => 'with-default-name'), $commandLoader->getArgument(1)); $this->assertEquals(array(array('with-default-name' => new ServiceClosureArgument(new TypedReference('with-default-name', NamedCommand::class)))), $commandLocator->getArguments()); - $this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_namedcommand' => 'with-default-name'), $container->getParameter('console.command.ids')); - $this->assertSame(array('with-default-name' => true), $container->getParameter('console.lazy_command.ids')); + $this->assertSame(array(), $container->getParameter('console.command.ids')); $container = new ContainerBuilder(); $container @@ -170,10 +167,9 @@ public function testProcessPrivateServicesWithSameCommand() (new AddConsoleCommandPass())->process($container); - $alias1 = 'console.command.symfony_component_console_tests_dependencyinjection_mycommand'; - $alias2 = $alias1.'_my-command2'; - $this->assertTrue($container->hasAlias($alias1)); - $this->assertTrue($container->hasAlias($alias2)); + $aliasPrefix = 'console.command.public_alias.'; + $this->assertTrue($container->hasAlias($aliasPrefix.'my-command1')); + $this->assertTrue($container->hasAlias($aliasPrefix.'my-command2')); } }