8000 Allow to register commands privately · symfony/symfony@ce324d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ce324d6

Browse files
committed
Allow to register commands privately
1 parent bb2727a commit ce324d6

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConsoleCommandPass.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ class AddConsoleCommandPass implements CompilerPassInterface
2424
public function process(ContainerBuilder $container)
2525
{
2626
$commandServices = $container->findTaggedServiceIds('console.command');
27+
$serviceIds = array();
2728

2829
foreach ($commandServices as $id => $tags) {
2930
$definition = $container->getDefinition($id);
3031

31-
if (!$definition->isPublic()) {
32-
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be public.', $id));
33-
}
34-
3532
if ($definition->isAbstract()) {
3633
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must not be abstract.', $id));
3734
}
@@ -40,9 +37,10 @@ public function process(ContainerBuilder $container)
4037
if (!is_subclass_of($class, 'Symfony\\Component\\Console\\Command\\Command')) {
4138
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be a subclass of "Symfony\\Component\\Console\\Command\\Command".', $id));
4239
}
43-
$container->setAlias('console.command.'.strtolower(str_replace('\\', '_', $class)), $id);
40+
$container->setAlias($serviceId = 'console.command.'.strtolower(str_replace('\\', '_', $class)), $id);
41+
$serviceIds[] = $serviceId;
4442
}
4543

46-
$container->setParameter('console.command.ids', array_keys($commandServices));
44+
$container->setParameter('console.command.ids', $serviceIds);
4745
}
4846
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,7 @@ public function testProcess()
3636
$this->assertSame('my-command', (string) $container->getAlias($alias));
3737

3838
$this->assertTrue($container->hasParameter('console.command.ids'));
39-
$this->assertSame(array('my-command'), $container->getParameter('console.command.ids'));
40-
}
41-
42-
/**
43-
* @expectedException \InvalidArgumentException
44-
* @expectedExceptionMessage The service "my-command" tagged "console.command" must be public.
45-
*/
46-
public function testProcessThrowAnExceptionIfTheServiceIsNotPublic()
47-
{
48-
$container = new ContainerBuilder();
49-
$container->addCompilerPass(new AddConsoleCommandPass());
50-
51-
$definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
52-
$definition->addTag('console.command');
53-
$definition->setPublic(false);
54-
$container->setDefinition('my-command', $definition);
55-
56-
$container->compile();
39+
$this->assertSame(array('console.command.symfony_bundle_frameworkbundle_tests_dependencyinjection_compiler_mycommand'), $container->getParameter('console.command.ids'));
5740
}
5841

5942
/**

0 commit comments

Comments
 (0)
0