%command.name% command sets ACL.
diff --git a/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php b/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php
index 1f6a5d3c6213b..c93cb4987f481 100644
--- a/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php
+++ b/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php
@@ -19,7 +19,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Security\Core\User\User;
@@ -33,6 +32,8 @@
*/
class UserPasswordEncoderCommand extends ContainerAwareCommand
{
+ protected static $defaultName = 'security:encode-password';
+
private $encoderFactory;
private $userClasses;
@@ -54,7 +55,6 @@ public function __construct(EncoderFactoryInterface $encoderFactory = null, arra
protected function configure()
{
$this
- ->setName('security:encode-password')
->setDescription('Encodes a password.')
->addArgument('password', InputArgument::OPTIONAL, 'The plain password to encode.')
->addArgument('user-class', InputArgument::OPTIONAL, 'The User entity class path associated with the encoder used to encode the password.')
diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php
index 1ceaca1002019..5ecbf47078afe 100644
--- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php
+++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php
@@ -20,7 +20,6 @@
* file that was distributed with this source code.
*/
use Symfony\Bundle\FrameworkBundle\Console\Application;
-use Symfony\Bundle\SecurityBundle\Command\InitAclCommand;
use Symfony\Bundle\SecurityBundle\Command\SetAclCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
@@ -170,7 +169,6 @@ private function getApplication()
$kernel->boot();
$application = new Application($kernel);
- $application->add(new InitAclCommand($kernel->getContainer()->get('security.acl.dbal.connection'), $kernel->getContainer()->get('security.acl.dbal.schema')));
$initAclCommand = $application->find('init:acl');
$initAclCommandTester = new CommandTester($initAclCommand);
diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json
index b1421742766de..38bf0220536d5 100644
--- a/src/Symfony/Bundle/SecurityBundle/composer.json
+++ b/src/Symfony/Bundle/SecurityBundle/composer.json
@@ -26,7 +26,7 @@
"require-dev": {
"symfony/asset": "~2.8|~3.0|~4.0",
"symfony/browser-kit": "~2.8|~3.0|~4.0",
- "symfony/console": "~3.2|~4.0",
+ "symfony/console": "~3.4|~4.0",
"symfony/css-selector": "~2.8|~3.0|~4.0",
"symfony/dom-crawler": "~2.8|~3.0|~4.0",
"symfony/event-dispatcher": "^3.3.1|~4.0",
@@ -47,7 +47,8 @@
},
"conflict": {
"symfony/var-dumper": "<3.3",
- "symfony/event-dispatcher": "<3.3.1"
+ "symfony/event-dispatcher": "<3.3.1",
+ "symfony/console": "<3.4"
},
"suggest": {
"symfony/security-acl": "For using the ACL functionality of this bundle"
diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md
index 0c147a605ccb2..24d7ff7af40e0 100644
--- a/src/Symfony/Component/Console/CHANGELOG.md
+++ b/src/Symfony/Component/Console/CHANGELOG.md
@@ -7,6 +7,10 @@ CHANGELOG
* added `CommandLoaderInterface`, `FactoryCommandLoader` and PSR-11
`ContainerCommandLoader` for commands lazy-loading
* added a case-insensitive command name matching fallback
+ * added static `Command::$defaultName/getDefaultName()`, allowing for
+ commands to be registered at compile time in the application command loader.
+ Setting the `$defaultName` property avoids the need for filling the `command`
+ attribute on the `console.command` tag when using `AddConsoleCommandPass`.
3.3.0
-----
diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php
index 6620ff5718c53..bd7059602d2f8 100644
--- a/src/Symfony/Component/Console/Command/Command.php
+++ b/src/Symfony/Component/Console/Command/Command.php
@@ -29,6 +29,11 @@
*/
class Command
{
+ /**
+ * @var string|null The default command name
+ */
+ protected static $defaultName;
+
private $application;
private $name;
private $processTitle;
@@ -45,6 +50,17 @@ class Command
private $usages = array();
private $helperSet;
+ /**
+ * @return string|null The default command name or null when no default name is set
+ */
+ public static function getDefaultName()
+ {
+ $class = get_called_class();
+ $r = new \ReflectionProperty($class, 'defaultName');
+
+ return $class === $r->class ? static::$defaultName : null;
+ }
+
/**
* Constructor.
*
@@ -56,7 +72,7 @@ public function __construct($name = null)
{
$this->definition = new InputDefinition();
- if (null !== $name) {
+ if (null !== $name || null !== $name = static::getDefaultName()) {
$this->setName($name);
}
diff --git a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php
index 67034098c218a..add7c5d0df491 100644
--- a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php
+++ b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php
@@ -46,16 +46,21 @@ public function process(ContainerBuilder $container)
$definition = $container->getDefinition($id);
$class = $container->getParameterBag()->resolveValue($definition->getClass());
- if (!$r = $container->getReflectionClass($class)) {
- throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
- }
- if (!$r->isSubclassOf(Command::class)) {
- throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
- }
-
$commandId = 'console.command.'.strtolower(str_replace('\\', '_', $class));
- if (!isset($tags[0]['command'])) {
+ if (isset($tags[0]['command'])) {
+ $commandName = $tags[0]['command'];
+ } else {
+ if (!$r = $container->getReflectionClass($class)) {
+ throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
+ }
+ if (!$r->isSubclassOf(Command::class)) {
+ throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
+ }
+ $commandName = $class::getDefaultName();
+ }
+
+ if (null === $commandName) {
if (isset($serviceIds[$commandId]) || $container->hasAlias($commandId)) {
$commandId = $commandId.'_'.$id;
}
@@ -69,7 +74,6 @@ public function process(ContainerBuilder $container)
}
$serviceIds[$commandId] = false;
- $commandName = $tags[0]['command'];
unset($tags[0]);
$lazyCommandMap[$commandName] = $id;
$lazyCommandRefs[$id] = new TypedReference($id, $class);
diff --git a/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php b/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php
index ddcee80145e53..807eb389730fe 100644
--- a/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php
+++ b/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php
@@ -77,6 +77,38 @@ public function testProcessRegistersLazyCommands()
$this->assertSame(array(array('setName', array('my:command')), array('setAliases', array(array('my:alias')))), $command->getMethodCalls());
}
+ public function testProcessFallsBackToDefaultName()
+ {
+ $container = new ContainerBuilder();
+ $container
+ ->register('with-default-name', NamedCommand::class)
+ ->setPublic(false)
+ ->addTag('console.command')
+ ;
+
+ $pass = new AddConsoleCommandPass();
+ $pass->process($container);
+
+ $commandLoader = $container->getDefinition('console.command_loader');
+ $commandLocator = $container->getDefinition((string) $commandLoader->getArgument(0));
+
+ $this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass());
+ $this->assertSame(array('default' => 'with-default-name'), $commandLoader->getArgument(1));
+ $this->assertEquals(array(array('with-default-name' => new ServiceClosureArgument(new TypedReference('with-default-name', NamedCommand::class)))), $commandLocator->getArguments());
+ $this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_namedcommand' => false), $container->getParameter('console.command.ids'));
+
+ $container = new ContainerBuilder();
+ $container
+ ->register('with-default-name', NamedCommand::class)
+ ->setPublic(false)
+ ->addTag('console.command', array('command' => 'new-name'))
+ ;
+
+ $pass->process($container);
+
+ $this->assertSame(array('new-name' => 'with-default-name'), $container->getDefinition('console.command_loader')->getArgument(1));
+ }
+
public function visibilityProvider()
{
return array(
@@ -96,7 +128,7 @@ public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
$container->addCompilerPass(new AddConsoleCommandPass());
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
- $definition->addTag('console.command', array('command' => 'my:command'));
+ $definition->addTag('console.command');
$definition->setAbstract(true);
$container->setDefinition('my-command', $definition);
@@ -114,7 +146,7 @@ public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
$container->addCompilerPass(new AddConsoleCommandPass());
$definition = new Definition('SplObjectStorage');
- $definition->addTag('console.command', array('command' => 'my:command'));
+ $definition->addTag('console.command');
$container->setDefinition('my-command', $definition);
$container->compile();
@@ -146,3 +178,8 @@ public function testProcessPrivateServicesWithSameCommand()
class MyCommand extends Command
{
}
+
+class NamedCommand extends Command
+{
+ protected static $defaultName = 'default';
+}
diff --git a/src/Symfony/Component/Translation/Command/XliffLintCommand.php b/src/Symfony/Component/Translation/Command/XliffLintCommand.php
index 80d8bb25dca2b..fead5edcb18bb 100644
--- a/src/Symfony/Component/Translation/Command/XliffLintCommand.php
+++ b/src/Symfony/Component/Translation/Command/XliffLintCommand.php
@@ -26,6 +26,8 @@
*/
class XliffLintCommand extends Command
{
+ protected static $defaultName = 'lint:xliff';
+
private $format;
private $displayCorrectFiles;
private $directoryIteratorProvider;
@@ -45,7 +47,6 @@ public function __construct($name = null, $directoryIteratorProvider = null, $is
protected function configure()
{
$this
- ->setName('lint:xliff')
->setDescription('Lints a XLIFF file and outputs encountered errors')
->addArgument('filename', null, 'A file or a directory or STDIN')
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
diff --git a/src/Symfony/Component/Yaml/Command/LintCommand.php b/src/Symfony/Component/Yaml/Command/LintCommand.php
index 36025bdebb8b7..202291551b57f 100644
--- a/src/Symfony/Component/Yaml/Command/LintCommand.php
+++ b/src/Symfony/Component/Yaml/Command/LintCommand.php
@@ -28,6 +28,8 @@
*/
class LintCommand extends Command
{
+ protected static $defaultName = 'lint:yaml';
+
private $parser;
private $format;
private $displayCorrectFiles;
@@ -48,7 +50,6 @@ public function __construct($name = null, $directoryIteratorProvider = null, $is
protected function configure()
{
$this
- ->setName('lint:yaml')
->setDescription('Lints a file and outputs encountered errors')
->addArgument('filename', null, 'A file or a directory or STDIN')
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
diff --git a/src/Symfony/Component/Yaml/composer.json b/src/Symfony/Component/Yaml/composer.json
index 41f04fb9f9543..a31a2cef426eb 100644
--- a/src/Symfony/Component/Yaml/composer.json
+++ b/src/Symfony/Component/Yaml/composer.json
@@ -19,7 +19,10 @@
"php": "^5.5.9|>=7.0.8"
},
"require-dev": {
- "symfony/console": "~2.8|~3.0|~4.0"
+ "symfony/console": "~3.4|~4.0"
+ },
+ "conflict": {
+ "symfony/console": "<3.4"
},
"suggest": {
"symfony/console": "For validating YAML files using the lint command"
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy