Move AddConsoleCommandPass from FrameworkBundle to Console.
This commit is contained in:
parent
cbecfc3d74
commit
7743989675
@ -27,6 +27,11 @@ Finder
|
||||
|
||||
* The `ExceptionInterface` has been deprecated and will be removed in 4.0.
|
||||
|
||||
FrameworkBundle
|
||||
---------------
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been deprecated. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
|
||||
|
||||
HttpKernel
|
||||
-----------
|
||||
|
||||
|
@ -151,6 +151,8 @@ FrameworkBundle
|
||||
`serializer.mapping.cache.apc` and `serializer.mapping.cache.doctrine.apc`
|
||||
have been removed. APCu should now be automatically used when available.
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been removed. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
|
||||
|
||||
SecurityBundle
|
||||
--------------
|
||||
|
||||
|
@ -11,6 +11,7 @@ CHANGELOG
|
||||
* Translation related services are not loaded anymore when the `framework.translator` option
|
||||
is disabled.
|
||||
* Added `GlobalVariables::getToken()`
|
||||
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass`. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
|
||||
|
||||
3.2.0
|
||||
-----
|
||||
|
@ -11,41 +11,17 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
@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);
|
||||
|
||||
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass as BaseAddConsoleCommandPass;
|
||||
|
||||
/**
|
||||
* AddConsoleCommandPass.
|
||||
* Registers console commands.
|
||||
*
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.
|
||||
*/
|
||||
class AddConsoleCommandPass implements CompilerPassInterface
|
||||
class AddConsoleCommandPass extends BaseAddConsoleCommandPass
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$commandServices = $container->findTaggedServiceIds('console.command');
|
||||
$serviceIds = array();
|
||||
|
||||
foreach ($commandServices as $id => $tags) {
|
||||
$definition = $container->getDefinition($id);
|
||||
|
||||
if ($definition->isAbstract()) {
|
||||
throw new InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must not be abstract.', $id));
|
||||
}
|
||||
|
||||
$class = $container->getParameterBag()->resolveValue($definition->getClass());
|
||||
if (!is_subclass_of($class, 'Symfony\\Component\\Console\\Command\\Command')) {
|
||||
if (!class_exists($class, false)) {
|
||||
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be a subclass of "Symfony\\Component\\Console\\Command\\Command".', $id));
|
||||
}
|
||||
$container->setAlias($serviceId = 'console.command.'.strtolower(str_replace('\\', '_', $class)), $id);
|
||||
$serviceIds[] = $definition->isPublic() ? $id : $serviceId;
|
||||
}
|
||||
|
||||
$container->setParameter('console.command.ids', $serviceIds);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ namespace Symfony\Bundle\FrameworkBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
|
||||
@ -36,6 +35,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
|
||||
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
||||
use Symfony\Component\Debug\ErrorHandler;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
||||
|
@ -17,6 +17,9 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AddConsoleCommandPassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@
|
||||
"require-dev": {
|
||||
"symfony/asset": "~2.8|~3.0",
|
||||
"symfony/browser-kit": "~2.8|~3.0",
|
||||
"symfony/console": "~2.8.8|~3.0.8|~3.1.2|~3.2",
|
||||
"symfony/console": "~3.3",
|
||||
"symfony/css-selector": "~2.8|~3.0",
|
||||
"symfony/dom-crawler": "~2.8|~3.0",
|
||||
"symfony/polyfill-intl-icu": "~1.0",
|
||||
@ -56,7 +56,8 @@
|
||||
},
|
||||
"conflict": {
|
||||
"phpdocumentor/reflection-docblock": "<3.0",
|
||||
"phpdocumentor/type-resolver": "<0.2.0"
|
||||
"phpdocumentor/type-resolver": "<0.2.0",
|
||||
"symfony/console": "<3.3"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-apcu": "For best performance of the system caches",
|
||||
|
@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
* added `AddConsoleCommandPass` (originally in FrameworkBundle)
|
||||
|
||||
3.2.0
|
||||
------
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Registers console commands.
|
||||
*
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
*/
|
||||
class AddConsoleCommandPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$commandServices = $container->findTaggedServiceIds('console.command');
|
||||
$serviceIds = array();
|
||||
|
||||
foreach ($commandServices as $id => $tags) {
|
||||
$definition = $container->getDefinition($id);
|
||||
|
||||
if ($definition->isAbstract()) {
|
||||
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must not be abstract.', $id));
|
||||
}
|
||||
|
||||
$class = $container->getParameterBag()->resolveValue($definition->getClass());
|
||||
if (!is_subclass_of($class, 'Symfony\\Component\\Console\\Command\\Command')) {
|
||||
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be a subclass of "Symfony\\Component\\Console\\Command\\Command".', $id));
|
||||
}
|
||||
$container->setAlias($serviceId = 'console.command.'.strtolower(str_replace('\\', '_', $class)), $id);
|
||||
$serviceIds[] = $definition->isPublic() ? $id : $serviceId;
|
||||
}
|
||||
|
||||
$container->setParameter('console.command.ids', $serviceIds);
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class AddConsoleCommandPassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider visibilityProvider
|
||||
*/
|
||||
public function testProcess($public)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
$container->setParameter('my-command.class', 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
|
||||
|
||||
$definition = new Definition('%my-command.class%');
|
||||
$definition->setPublic($public);
|
||||
$definition->addTag('console.command');
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$id = $public ? 'my-command' : 'console.command.symfony_component_console_tests_dependencyinjection_mycommand';
|
||||
$this->assertTrue($container->hasParameter('console.command.ids'));
|
||||
$this->assertSame(array($id), $container->getParameter('console.command.ids'));
|
||||
}
|
||||
|
||||
public function visibilityProvider()
|
||||
{
|
||||
return array(
|
||||
array(true),
|
||||
array(false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
|
||||
*/
|
||||
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
|
||||
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
|
||||
$definition->addTag('console.command');
|
||||
$definition->setAbstract(true);
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".
|
||||
*/
|
||||
public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
|
||||
$definition = new Definition('SplObjectStorage');
|
||||
$definition->addTag('console.command');
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
}
|
||||
|
||||
class MyCommand extends Command
|
||||
{
|
||||
}
|
||||
|
||||
class ExtensionPresentBundle extends Bundle
|
||||
{
|
||||
}
|
@ -21,7 +21,9 @@
|
||||
"symfony/debug": "~2.8|~3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/http-kernel": "~2.8|~3.0",
|
||||
"symfony/event-dispatcher": "~2.8|~3.0",
|
||||
"symfony/dependency-injection": "~2.8|~3.0",
|
||||
"symfony/filesystem": "~2.8|~3.0",
|
||||
"symfony/process": "~2.8|~3.0",
|
||||
"psr/log": "~1.0"
|
||||
|
Reference in New Issue
Block a user