Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit6e57865

Browse files
committed
Move AddConsoleCommandPass from FrameworkBundle to Console.
1 parent194dcf3 commit6e57865

File tree

8 files changed

+176
-3
lines changed

8 files changed

+176
-3
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
namespaceSymfony\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
useSymfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1517
useSymfony\Component\DependencyInjection\ContainerBuilder;
1618

1719
/**
18-
*AddConsoleCommandPass.
20+
*Registers console commands.
1921
*
2022
* @author Grégoire Pineau <lyrixx@lyrixx.info>
23+
*
24+
* @deprecated since version 3.2, to be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.
2125
*/
2226
class AddConsoleCommandPassimplements CompilerPassInterface
2327
{

‎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
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
1515
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
16-
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
16+
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPassasLegacyAddConsoleCommandPass;
1717
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
1818
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
1919
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
@@ -33,6 +33,7 @@
3333
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
3434
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
3535
useSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
36+
useSymfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
3637
useSymfony\Component\Debug\ErrorHandler;
3738
useSymfony\Component\DependencyInjection\ContainerBuilder;
3839
useSymfony\Component\DependencyInjection\Compiler\PassConfig;
@@ -77,7 +78,6 @@ public function build(ContainerBuilder $container)
7778
$container->addCompilerPass(newTemplatingPass());
7879
$container->addCompilerPass(newAddConstraintValidatorsPass());
7980
$container->addCompilerPass(newAddValidatorInitializersPass());
80-
$container->addCompilerPass(newAddConsoleCommandPass());
8181
$container->addCompilerPass(newFormPass());
8282
$container->addCompilerPass(newTranslatorPass());
8383
$container->addCompilerPass(newLoggingTranslatorPass());
@@ -92,6 +92,12 @@ public function build(ContainerBuilder $container)
9292
$container->addCompilerPass(newControllerArgumentValueResolverPass());
9393
$container->addCompilerPass(newCachePoolPass());
9494

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

‎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 <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+
namespaceSymfony\Component\Console\DependencyInjection;
13+
14+
useSymfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
useSymfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* Registers console commands.
19+
*
20+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
21+
*/
22+
class AddConsoleCommandPassimplements CompilerPassInterface
23+
{
24+
publicfunctionprocess(ContainerBuilder$container)
25+
{
26+
$commandServices =$container->findTaggedServiceIds('console.command');
27+
$serviceIds =array();
28+
29+
foreach ($commandServicesas$id =>$tags) {
30+
$definition =$container->getDefinition($id);
31+
32+
if ($definition->isAbstract()) {
33+
thrownew \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+
thrownew \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: 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+
namespaceSymfony\Component\Console\Tests\DependencyInjection;
13+
14+
useSymfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
15+
useSymfony\Component\Console\Command\Command;
16+
useSymfony\Component\DependencyInjection\ContainerBuilder;
17+
useSymfony\Component\DependencyInjection\Definition;
18+
useSymfony\Component\HttpKernel\Bundle\Bundle;
19+
20+
class AddConsoleCommandPassTestextends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @dataProvider visibilityProvider
24+
*/
25+
publicfunctiontestProcess($public)
26+
{
27+
$container =newContainerBuilder();
28+
$container->addCompilerPass(newAddConsoleCommandPass());
29+
$container->setParameter('my-command.class','Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
30+
31+
$definition =newDefinition('%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+
publicfunctionvisibilityProvider()
44+
{
45+
returnarray(
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+
publicfunctiontestProcessThrowAnExceptionIfTheServiceIsAbstract()
56+
{
57+
$container =newContainerBuilder();
58+
$container->addCompilerPass(newAddConsoleCommandPass());
59+
60+
$definition =newDefinition('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+
publicfunctiontestProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
73+
{
74+
$container =newContainerBuilder();
75+
$container->addCompilerPass(newAddConsoleCommandPass());
76+
77+
$definition =newDefinition('SplObjectStorage');
78+
$definition->addTag('console.command');
79+
$container->setDefinition('my-command',$definition);
80+
81+
$container->compile();
82+
}
83+
84+
publicfunctiontestHttpKernelRegisterCommandsIngoreCommandAsAService()
85+
{
86+
$container =newContainerBuilder();
87+
$container->addCompilerPass(newAddConsoleCommandPass());
88+
$definition =newDefinition('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 =newExtensionPresentBundle();
100+
101+
$bundle->setContainer($container);
102+
$bundle->registerCommands($application);
103+
}
104+
}
105+
106+
class MyCommandextends Command
107+
{
108+
}
109+
110+
class ExtensionPresentBundleextends Bundle
111+
{
112+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
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"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp