Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db03053

Browse filesBrowse files
committed
Move AddConsoleCommandPass from FrameworkBundle to Console.
1 parent 835176c commit db03053
Copy full SHA for db03053

File tree

8 files changed

+176
-3
lines changed
Filter options

8 files changed

+176
-3
lines changed

‎UPGRADE-3.2.md

Copy file name to clipboardExpand all lines: UPGRADE-3.2.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ FrameworkBundle
66

77
* The `Controller::getUser()` method has been deprecated and will be removed in
88
Symfony 4.0; typehint the security user object in the action instead.
9+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been deprecated. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
910

1011
DependencyInjection
1112
-------------------

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* The `Controller::getUser()` method has been deprecated and will be removed in
88
Symfony 4.0; typehint the security user object in the action instead.
99
* Added possibility to prioritize form type extensions with `'priority'` attribute on tags `form.type_extension`
10+
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass`. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
1011

1112
3.1.0
1213
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConsoleCommandPass.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.', AddConsoleCommandPass::class), E_USER_DEPRECATED);
15+
1416
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1517
use Symfony\Component\DependencyInjection\ContainerBuilder;
1618
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1719

1820
/**
19-
* AddConsoleCommandPass.
21+
* Registers console commands.
2022
*
2123
* @author Grégoire Pineau <lyrixx@lyrixx.info>
24+
*
25+
* @deprecated since version 3.2, to be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.
2226
*/
2327
class AddConsoleCommandPass implements CompilerPassInterface
2428
{

‎src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
16-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
16+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass as LegacyAddConsoleCommandPass;
1717
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
1818
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
1919
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
@@ -34,6 +34,7 @@
3434
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
3535
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
3636
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
37+
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
3738
use Symfony\Component\Debug\ErrorHandler;
3839
use Symfony\Component\DependencyInjection\ContainerBuilder;
3940
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
@@ -78,7 +79,6 @@ public function build(ContainerBuilder $container)
7879
$container->addCompilerPass(new TemplatingPass());
7980
$container->addCompilerPass(new AddConstraintValidatorsPass());
8081
$container->addCompilerPass(new AddValidatorInitializersPass());
81-
$container->addCompilerPass(new AddConsoleCommandPass());
8282
$container->addCompilerPass(new FormPass());
8383
$container->addCompilerPass(new TranslatorPass());
8484
$container->addCompilerPass(new LoggingTranslatorPass());
@@ -94,6 +94,12 @@ public function build(ContainerBuilder $container)
9494
$container->addCompilerPass(new CachePoolPass());
9595
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
9696

97+
if (class_exists(AddConsoleCommandPass::class)) {
98+
$container->addCompilerPass(new AddConsoleCommandPass());
99+
} else {
100+
$container->addCompilerPass(new LegacyAddConsoleCommandPass());
101+
}
102+
97103
if ($container->getParameter('kernel.debug')) {
98104
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
99105
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);

‎src/Symfony/Component/Console/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* added `setStream()` and `getStream()` methods to Input (implement StreamableInputInterface)
99
* added StreamableInputInterface
1010
* added LockableTrait
11+
* added `AddConsoleCommandPass` (originally in FrameworkBundle)
1112

1213
3.1.0
1314
-----
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* Registers console commands.
19+
*
20+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
21+
*/
22+
class AddConsoleCommandPass implements CompilerPassInterface
23+
{
24+
public function process(ContainerBuilder $container)
25+
{
26+
$commandServices = $container->findTaggedServiceIds('console.command');
27+
$serviceIds = array();
28+
29+
foreach ($commandServices as $id => $tags) {
30+
$definition = $container->getDefinition($id);
31+
32+
if ($definition->isAbstract()) {
33+
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must not be abstract.', $id));
34+
}
35+
36+
$class = $container->getParameterBag()->resolveValue($definition->getClass());
37+
if (!is_subclass_of($class, 'Symfony\\Component\\Console\\Command\\Command')) {
38+
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be a subclass of "Symfony\\Component\\Console\\Command\\Command".', $id));
39+
}
40+
$container->setAlias($serviceId = 'console.command.'.strtolower(str_replace('\\', '_', $class)), $id);
41+
$serviceIds[] = $definition->isPublic() ? $id : $serviceId;
42+
}
43+
44+
$container->setParameter('console.command.ids', $serviceIds);
45+
}
46+
}
+112Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\DependencyInjection;
13+
14+
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
15+
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Definition;
18+
use Symfony\Component\HttpKernel\Bundle\Bundle;
19+
20+
class AddConsoleCommandPassTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @dataProvider visibilityProvider
24+
*/
25+
public function testProcess($public)
26+
{
27+
$container = new ContainerBuilder();
28+
$container->addCompilerPass(new AddConsoleCommandPass());
29+
$container->setParameter('my-command.class', 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
30+
31+
$definition = new Definition('%my-command.class%');
32+
$definition->setPublic($public);
33+
$definition->addTag('console.command');
34+
$container->setDefinition('my-command', $definition);
35+
36+
$container->compile();
37+
38+
$id = $public ? 'my-command' : 'console.command.symfony_component_console_tests_dependencyinjection_mycommand';
39+
$this->assertTrue($container->hasParameter('console.command.ids'));
40+
$this->assertSame(array($id), $container->getParameter('console.command.ids'));
41+
}
42+
43+
public function visibilityProvider()
44+
{
45+
return array(
46+
array(true),
47+
array(false),
48+
);
49+
}
50+
51+
/**
52+
* @expectedException \InvalidArgumentException
53+
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
54+
*/
55+
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
56+
{
57+
$container = new ContainerBuilder();
58+
$container->addCompilerPass(new AddConsoleCommandPass());
59+
60+
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
61+
$definition->addTag('console.command');
62+
$definition->setAbstract(true);
63+
$container->setDefinition('my-command', $definition);
64+
65+
$container->compile();
66+
}
67+
68+
/**
69+
* @expectedException \InvalidArgumentException
70+
* @expectedExceptionMessage The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".
71+
*/
72+
public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
73+
{
74+
$container = new ContainerBuilder();
75+
$container->addCompilerPass(new AddConsoleCommandPass());
76+
77+
$definition = new Definition('SplObjectStorage');
78+
$definition->addTag('console.command');
79+
$container->setDefinition('my-command', $definition);
80+
81+
$container->compile();
82+
}
83+
84+
public function testHttpKernelRegisterCommandsIngoreCommandAsAService()
85+
{
86+
$container = new ContainerBuilder();
87+
$container->addCompilerPass(new AddConsoleCommandPass());
88+
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
89+
$definition->addTag('console.command');
90+
$container->setDefinition('my-command', $definition);
91+
$container->compile();
92+
93+
$application = $this->getMock('Symfony\Component\Console\Application');
94+
// Never called, because it's the
95+
// Symfony\Bundle\FrameworkBundle\Console\Application that register
96+
// commands as a service
97+
$application->expects($this->never())->method('add');
98+
99+
$bundle = new ExtensionPresentBundle();
100+
101+
$bundle->setContainer($container);
102+
$bundle->registerCommands($application);
103+
}
104+
}
105+
106+
class MyCommand extends Command
107+
{
108+
}
109+
110+
class ExtensionPresentBundle extends Bundle
111+
{
112+
}

‎src/Symfony/Component/Console/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/composer.json
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"symfony/debug": "~2.8|~3.0"
2222
},
2323
"require-dev": {
24+
"symfony/http-kernel": "~2.8|~3.0",
2425
"symfony/event-dispatcher": "~2.8|~3.0",
26+
"symfony/dependency-injection": "~2.8|~3.0",
2527
"symfony/filesystem": "~2.8|~3.0",
2628
"symfony/process": "~2.8|~3.0",
2729
"psr/log": "~1.0"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.