10000 Fix registering lazy command services with autoconfigure enabled · symfony/symfony@8a71aa3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a71aa3

Browse files
author
Robin Chalas
committed
Fix registering lazy command services with autoconfigure enabled
1 parent 5352080 commit 8a71aa3

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,15 @@ public function process(ContainerBuilder $container)
7070

7171
$serviceIds[$commandId] = false;
7272
$commandName = $tags[0]['command'];
73+
unset($tags[0]);
7374
$lazyCommandMap[$commandName] = $id;
7475
$lazyCommandRefs[$id] = new TypedReference($id, $class);
7576
$aliases = array();
7677

7778
foreach ($tags as $tag) {
78-
if (!isset($tag['command'])) {
79-
throw new InvalidArgumentException(sprintf('Missing "command" attribute on tag "%s" for service "%s".', $this->commandTag, $id));
80-
}
81-
if ($commandName !== $tag['command']) {
82-
throw new InvalidArgumentException(sprintf('The "command" attribute must be the same on each "%s" tag for service "%s".', $this->commandTag, $id));
83-
}
84-
if (isset($tag['alias'])) {
85-
$aliases[] = $tag['alias'];
86-
$lazyCommandMap[$tag['alias']] = $id;
79+
if (isset($tag['command'])) {
80+
$aliases[] = $tag['command'];
81+
$lazyCommandMap[$tag['command']] = $id;
8782
}
8883
}
8984

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,9 @@ public function testRunLazyCommandService()
14311431
$container->addCompilerPass(new AddConsoleCommandPass());
14321432
$container
14331433
->register('lazy-command', LazyCommand::class)
1434-
->addTag('console.command', array('command' => 'lazy:command', 'alias' => 'lazy:alias'))
1435-
->addTag('console.command', array('command' => 'lazy:command', 'alias' => 'lazy:alias2'));
1434+
->addTag('console.command', array('command' => 'lazy:command'))
1435+
->addTag('console.command', array('command' => 'lazy:alias'))
1436+
->addTag('console.command', array('command' => 'lazy:alias2'));
14361437
$container->compile();
14371438

14381439
$application = new Application();

src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ public function testProcess($public)
5656
$this->assertSame(array($alias => $id), $container->getParameter('console.command.ids'));
5757
}
5858

59-
public function testProcessRegisterLazyCommands()
59+
public function testProcessRegistersLazyCommands()
6060
{
6161
$container = new ContainerBuilder();
62-
$container
62+
$command = $container
6363
->register('my-command', MyCommand::class)
6464
->setPublic(false)
65-
->addTag('console.command', array('command' => 'my:command', 'alias' => 'my:alias'))
65+
->addTag('console.command', array('command' => 'my:command'))
66+
->addTag('console.command', array('command' => 'my:alias'))
6667
;
6768

6869
(new AddConsoleCommandPass())->process($container);
@@ -74,6 +75,7 @@ public function testProcessRegisterLazyCommands()
7475
$this->assertSame(array('my:command' => 'my-command', 'my:alias' => 'my-command'), $commandLoader->getArgument(1));
7576
$this->assertEquals(array(array('my-command' => new ServiceClosureArgument(new TypedReference('my-command', MyCommand::class)))), $commandLocator->getArguments());
7677
$this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_mycommand' => false), $container->getParameter('console.command.ids'));
78+
$this->assertSame(array(array('setName', array('my:command')), array('setAliases', array(array('my:alias')))), $command->getMethodCalls());
7779
}
7880

7981
public function visibilityProvider()

0 commit comments

Comments
 (0)
0