8000 feature #19443 [Console] Move AddConsoleCommandPass from FrameworkBun… · symfony/symfony@294a877 · GitHub
[go: up one dir, main page]

Skip to content

Commit 294a877

Browse files
committed
feature #19443 [Console] Move AddConsoleCommandPass from FrameworkBundle to Console. (bcremer)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Console] Move AddConsoleCommandPass from FrameworkBundle to Console. | Q | A | | --- | --- | | Branch? | master | | Bug fix? | no | | New feature? | yes | | BC breaks? | yes | | Deprecations? | yes | | Tests pass? | yes | | Fixed tickets | #19440 | | License | MIT | | Doc PR | - | Commits ------- 7743989 Move AddConsoleCommandPass from FrameworkBundle to Console.
2 parents cbecfc3 + 7743989 commit 294a877

File tree

11 files changed

+169
-34
lines changed

11 files changed

+169
-34
lines changed

UPGRADE-3.3.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ Finder
2626
------
2727

2828
* The `ExceptionInterface` has been deprecated and will be removed in 4.0.
29+
30+
FrameworkBundle
31+
---------------
2932

33+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been deprecated. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
34+
3035
HttpKernel
3136
-----------
3237

UPGRADE-4.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ FrameworkBundle
150150
* The `framework.serializer.cache` option and the services
151151
`serializer.mapping.cache.apc` and `serializer.mapping.cache.doctrine.apc`
152152
have been removed. APCu should now be automatically used when available.
153+
154+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been removed. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
153155

154156
SecurityBundle
155157
--------------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Translation related services are not loaded anymore when the `framework.translator` option
1212
is disabled.
1313
* Added `GlobalVariables::getToken()`
14+
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass`. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
1415

1516
3.2.0
1617
-----

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,17 @@
1111

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

14-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
14+
@trigger_error(sprintf('%s is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.', AddConsoleCommandPass::class), E_USER_DEPRECATED);
15+
16+
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass as BaseAddConsoleCommandPass;
1717

1818
/**
19-
* AddConsoleCommandPass.
19+
* Registers console commands.
2020
*
2121
* @author Grégoire Pineau <lyrixx@lyrixx.info>
22+
*
23+
* @deprecated since version 3.3, to be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.
2224
*/
23-
class AddConsoleCommandPass implements CompilerPassInterface
25+
class AddConsoleCommandPass extends BaseAddConsoleCommandPass
2426
{
25-
public function process(ContainerBuilder $container)
26-
{
27-
$commandServices = $container->findTaggedServiceIds('console.command');
28-
$serviceIds = array();
29-
30-
foreach ($commandServices as $id => $tags) {
31-
$definition = $container->getDefinition($id);
32-
33-
if ($definition->isAbstract()) {
34-
throw new InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must not be abstract.', $id));
35-
}
36-
37-
$class = $container->getParameterBag()->resolveValue($definition->getClass());
38-
if (!is_subclass_of($class, 'Symfony\\Component\\Console\\Command\\Command')) {
39-
if (!class_exists($class, false)) {
40-
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
41-
}
42-
43-
throw new InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be a subclass of "Symfony\\Component\\Console\\Command\\Command".', $id));
44-
}
45-
$container->setAlias($serviceId = 'console.command.'.strtolower(str_replace('\\', '_', $class)), $id);
46-
$serviceIds[] = $definition->isPublic() ? $id : $serviceId;
47-
}
48-
49-
$container->setParameter('console.command.ids', $serviceIds);
50-
}
5127
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
1616
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
17-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
1817
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
1918
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
2019
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
@@ -36,6 +35,7 @@
3635
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
3736
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
3837
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
38+
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
3939
use Symfony\Component\Debug\ErrorHandler;
4040
use Symfony\Component\DependencyInjection\ContainerBuilder;
4141
use Symfony\Component\DependencyInjection\Compiler\PassConfig;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Symfony\Component\DependencyInjection\Definition;
1818
use Symfony\Component\HttpKernel\Bundle\Bundle;
1919

20+
/**
21+
* @group legacy
22+
*/
2023
class AddConsoleCommandPassTest extends \PHPUnit_Framework_TestCase
2124
{
2225
/**

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"require-dev": {
3535
"symfony/asset": "~2.8|~3.0",
3636
"symfony/browser-kit": "~2.8|~3.0",
37-
"symfony/console": "~2.8.8|~3.0.8|~3.1.2|~3.2",
37+
"symfony/console": "~3.3",
3838
"symfony/css-selector": "~2.8|~3.0",
3939
"symfony/dom-crawler": "~2.8|~3.0",
4040
"symfony/polyfill-intl-icu": "~1.0",
@@ -56,7 +56,8 @@
5656
},
5757
"conflict": {
5858
"phpdocumentor/reflection-docblock": "<3.0",
59-
"phpdocumentor/type-resolver": "<0.2.0"
59+
"phpdocumentor/type-resolver": "<0.2.0",
60+
"symfony/console": "<3.3"
6061
},
6162
"suggest": {
6263
"ext-apcu": "For best performance of the system caches",

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* added `AddConsoleCommandPass` (originally in FrameworkBundle)
8+
49
3.2.0
510
------
611

Lines 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+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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->setResourceTracking(false);
29+
$container->addCompilerPass(new AddConsoleCommandPass());
30+
$container->setParameter('my-command.class', 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
31+
32+
$definition = new Definition('%my-command.class%');
33+
$definition->setPublic($public);
34+
$definition->addTag('console.command');
35+
$container->setDefinition('my-command', $definition);
36+
37+
$container->compile();
38+
39+
$id = $public ? 'my-command' : 'console.command.symfony_component_console_tests_dependencyinjection_mycommand';
40+
$this->assertTrue($container->hasParameter('console.command.ids'));
41+
$this->assertSame(array($id), $container->getParameter('console.command.ids'));
42+
}
43+
44+
public function visibilityProvider()
45+
{
46+
return array(
47+
array(true),
48+
array(false),
49+
);
50+
}
51+
52+
/**
53+
* @expectedException \InvalidArgumentException
54+
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
55+
*/
56+
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
57+
{
58+
$container = new ContainerBuilder();
59+
$container->setResourceTracking(false);
60+
$container->addCompilerPass(new AddConsoleCommandPass());
61+
62+
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
63+
$definition->addTag('console.command');
64+
$definition->setAbstract(true);
65+
$container->setDefinition('my-command', $definition);
66+
67+
$container->compile();
68+
}
69+
70+
/**
71+
* @expectedException \InvalidArgumentException
72+
* @expectedExceptionMessage The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".
73+
*/
74+
public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
75+
{
76+
$container = new ContainerBuilder();
77+
$container->setResourceTracking(false);
78+
$container->addCompilerPass(new AddConsoleCommandPass());
79+
80+
$definition = new Definition('SplObjectStorage');
81+
$definition->addTag('console.command');
82+
$container->setDefinition('my-command', $definition);
83+
84+
$container->compile();
85+
}
86+
}
87+
88+
class MyCommand extends Command
89+
{
90+
}
91+
92+
class ExtensionPresentBundle extends Bundle
93+
{
94+
}

src/Symfony/Component/Console/composer.json

Lines 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