Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dffd5e6

Browse files
bcremershopwareBot
authored and
shopwareBot
committed
Move AddConsoleCommandPass from FrameworkBundle to Console.
Close issue #19440.
1 parent 194dcf3 commit dffd5e6

File tree

9 files changed

+74
-18
lines changed

9 files changed

+74
-18
lines changed

UPGRADE-3.2.md

Lines 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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
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+
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass`. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
910

1011
3.1.0
1112
-----

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
* AddConsoleCommandPass.
1919
*
2020
* @author Grégoire Pineau <[email protected]>
21+
* @deprecated since version 3.2, to be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.
2122
*/
2223
class AddConsoleCommandPass implements CompilerPassInterface
2324
{
25+
public function __construct()
26+
{
27+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.', __CLASS__), E_USER_DEPRECATED);
28+
}
29+
2430
public function process(ContainerBuilder $container)
2531
{
2632
$commandServices = $container->findTaggedServiceIds('console.command');

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines 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 DeprecatedAddConsoleCommandPass;
1717
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
1818
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
1919
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
@@ -33,6 +33,7 @@
3333
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
3434
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
3535
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
36+
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
3637
use Symfony\Component\Debug\ErrorHandler;
3738
use Symfony\Component\DependencyInjection\ContainerBuilder;
3839
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
@@ -77,7 +78,6 @@ public function build(ContainerBuilder $container)
7778
$container->addCompilerPass(new TemplatingPass());
7879
$container->addCompilerPass(new AddConstraintValidatorsPass());
7980
$container->addCompilerPass(new AddValidatorInitializersPass());
80-
$container->addCompilerPass(new AddConsoleCommandPass());
8181
$container->addCompilerPass(new FormPass());
8282
$container->addCompilerPass(new TranslatorPass());
8383
$container->addCompilerPass(new LoggingTranslatorPass());
@@ -92,6 +92,12 @@ public function build(ContainerBuilder $container)
9292
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
9393
$container->addCompilerPass(new CachePoolPass());
9494

95+
if (class_exists(AddConsoleCommandPass::class)) {
96+
$container->addCompilerPass(new AddConsoleCommandPass());
97+
} else {
98+
$container->addCompilerPass(new DeprecatedAddConsoleCommandPass());
99+
}
100+
95101
if ($container->getParameter('kernel.debug')) {
96102
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
97103
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"symfony/class-loader": "~3.2",
2323
"symfony/dependency-injection": "~3.2",
2424
"symfony/config": "~2.8|~3.0",
25+
"symfony/console": "~3.2",
2526
"symfony/event-dispatcher": "~2.8|~3.0",
2627
"symfony/http-foundation": "~3.1",
2728
"symfony/http-kernel": "~3.1.2|~3.2",

src/Symfony/Component/Console/CHANGELOG.md

Lines 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
-----
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 <[email protected]>
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+
* AddConsoleCommandPass.
19+
*
20+
* @author Grégoire Pineau <[email protected]>
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: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
12+
namespace Symfony\Component\Console\Tests\DependencyInjection;
1313

14-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
14+
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
1515
use Symfony\Component\Console\Command\Command;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Definition;
@@ -26,7 +26,7 @@ public function testProcess($public)
2626
{
2727
$container = new ContainerBuilder();
2828
$container->addCompilerPass(new AddConsoleCommandPass());
29-
$container->setParameter('my-command.class', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
29+
$container->setParameter('my-command.class', 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
3030

3131
$definition = new Definition('%my-command.class%');
3232
$definition->setPublic($public);
@@ -35,17 +35,7 @@ public function testProcess($public)
3535

3636
$container->compile();
3737

38-
$alias = 'console.command.symfony_bundle_frameworkbundle_tests_dependencyinjection_compiler_mycommand';
39-
if ($container->hasAlias($alias)) {
40-
$this->assertSame('my-command', (string) $container->getAlias($alias));
41-
} else {
42-
// The alias is replaced by a Definition by the ReplaceAliasByActualDefinitionPass
43-
// in case the original service is private
44-
$this->assertFalse($container->hasDefinition('my-command'));
45-
$this->assertTrue($container->hasDefinition($alias));
46-
}
47-
48-
$id = $public ? 'my-command' : 'console.command.symfony_bundle_frameworkbundle_tests_dependencyinjection_compiler_mycommand';
38+
$id = $public ? 'my-command' : 'console.command.symfony_component_console_tests_dependencyinjection_mycommand';
4939
$this->assertTrue($container->hasParameter('console.command.ids'));
5040
$this->assertSame(array($id), $container->getParameter('console.command.ids'));
5141
}
@@ -67,7 +57,7 @@ public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
6757
$container = new ContainerBuilder();
6858
$container->addCompilerPass(new AddConsoleCommandPass());
6959

70-
$definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
60+
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
7161
$definition->addTag('console.command');
7262
$definition->setAbstract(true);
7363
$container->setDefinition('my-command', $definition);
@@ -95,7 +85,7 @@ public function testHttpKernelRegisterCommandsIngoreCommandAsAService()
9585
{
9686
$container = new ContainerBuilder();
9787
$container->addCompilerPass(new AddConsoleCommandPass());
98-
$definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
88+
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
9989
$definition->addTag('console.command');
10090
$container->setDefinition('my-command', $definition);
10191
$container->compile();
@@ -107,6 +97,7 @@ public function testHttpKernelRegisterCommandsIngoreCommandAsAService()
10797
$application->expects($this->never())->method('add');
10898

10999
$bundle = new ExtensionPresentBundle();
100+
110101
$bundle->setContainer($container);
111102
$bundle->registerCommands($application);
112103
}

src/Symfony/Component/Console/composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
"symfony/polyfill-mbstring": "~1.0"
2121
},
2222
"require-dev": {
23+
"symfony/http-kernel": "~2.8|~3.0",
2324
"symfony/event-dispatcher": "~2.8|~3.0",
25+
"symfony/dependency-injection": "~2.8|~3.0",
2426
"symfony/filesystem": "~2.8|~3.0",
2527
"symfony/process": "~2.8|~3.0",
2628
"psr/log": "~1.0"
2729
},
2830
"suggest": {
31+
"symfony/dependency-injection": "",
2932
"symfony/event-dispatcher": "",
3033
"symfony/filesystem": "",
3134
"symfony/process": "",

0 commit comments

Comments
 (0)