8000 [Console] Add protected static $defaultName to set the default name o… · symfony/symfony@e431d33 · GitHub
[go: up one dir, main page]

Skip to content

Commit e431d33

Browse files
nicolas-grekaschalasr
authored andcommitted
[Console] Add protected static $defaultName to set the default name of a Command
1 parent 5d9ae6b commit e431d33

28 files changed

+63
-40
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
class DebugCommand extends Command
2828
{
29+
protected static $defaultName = 'debug:twig';
30+
2931
private $twig;
3032

3133
/**

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*/
3232
class LintCommand extends Command
3333
{
34+
protected static $defaultName = 'lint:twig';
35+
3436
private $twig;
3537

3638
/**

src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
class AboutCommand extends ContainerAwareCommand
3030
{
31+
protected static $defaultName = 'about';
32+
3133
/**
3234
* {@inheritdoc}
3335
*/

src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class AssetsInstallCommand extends ContainerAwareCommand
3535
const METHOD_ABSOLUTE_SYMLINK = 'absolute symlink';
3636
const METHOD_RELATIVE_SYMLINK = 'relative symlink';
3737

38+
protected static $defaultName = 'assets:install';
39+
3840
private $filesystem;
3941

4042
/**

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*/
3232
class CacheClearCommand extends ContainerAwareCommand
3333
{
34+
protected static $defaultName = 'cache:clear';
35+
3436
private $cacheClearer;
3537
private $filesystem;
3638

src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
final class CachePoolClearCommand extends ContainerAwareCommand
2727
{
28+
protected static $defaultName = 'cache:pool:clear';
29+
2830
private $poolClearer;
2931

3032
/**

src/Symfony/Bundle/FrameworkBundle/Command/CachePoolPruneCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
final class CachePoolPruneCommand extends Command
2626
{
27+
protected static $defaultName = 'cache:pool:prune';
28+
2729
private $pools;
2830

2931
/**

src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
class CacheWarmupCommand extends ContainerAwareCommand
2828
{
29+
protected static $defaultName = 'cache:warmup';
30+
2931
private $cacheWarmer;
3032

3133
/**

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
class ConfigDebugCommand extends AbstractConfigCommand
3030
{
31+
protected static $defaultName = 'debug:config';
32+
3133
/**
3234
* {@inheritdoc}
3335
*/

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
*/
3131
class ConfigDumpReferenceCommand extends AbstractConfigCommand
3232
{
33+
protected static $defaultName = 'config:dump-reference';
34+
3335
/**
3436
* {@inheritdoc}
3537
*/

src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
class ContainerDebugCommand extends ContainerAwareCommand
3434
{
35+
protected static $defaultName = 'debug:container';
36+
3537
/**
3638
* @var ContainerBuilder|null
3739
*/

src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
class EventDispatcherDebugCommand extends ContainerAwareCommand
3030
{
31+
protected static $defaultName = 'debug:event-dispatcher';
3132
private $dispatcher;
3233

3334
/**

src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333
class RouterDebugCommand extends ContainerAwareCommand
3434
{
35+
protected static $defaultName = 'debug:router';
3536
private $router;
3637

3738
/**

src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
class RouterMatchCommand extends ContainerAwareCommand
3131
{
32+
protected static $defaultName = 'router:match';
33+
3234
private $router;
3335

3436
/**

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class TranslationDebugCommand extends ContainerAwareCommand
4040
const MESSAGE_UNUSED = 1;
4141
const MESSAGE_EQUALS_FALLBACK = 2;
4242

43+
protected static $defaultName = 'debug:translation';
44+
4345
private $translator;
4446
private $loader;
4547
private $extractor;

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
*/
3434
class TranslationUpdateCommand extends ContainerAwareCommand
3535
{
36+
protected static $defaultName = 'translation:update';
37+
3638
private $writer;
3739
private $loader;
3840
private $extractor;

src/Symfony/Bundle/FrameworkBundle/Command/WorkflowDumpCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class WorkflowDumpCommand extends ContainerAwareCommand
2727
{
28+
protected static $defaultName = 'workflow:dump';
29+
2830
/**
2931
* {@inheritdoc}
3032
*

src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
class InitAclCommand extends ContainerAwareCommand
2929
{
30+
protected static $defaultName = 'init:acl';
31+
3032
private $connection;
3133
private $schema;
3234

@@ -70,7 +72,6 @@ public function isEnabled()
7072
protected function configure()
7173
{
7274
$this
73-
->setName('init:acl')
7475
->setDescription('Mounts ACL tables in the database')
7576
->setHelp(<<<'EOF'
7677
The <info>%command.name%</info> command mounts ACL tables in the database.

src/Symfony/Bundle/SecurityBundle/Command/SetAclCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
class SetAclCommand extends ContainerAwareCommand
3434
{
35+
protected static $defaultName = 'acl:set';
36+
3537
private $provider;
3638

3739
/**

src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Symfony\Component\Console\Output\OutputInterface;
2020
use Symfony\Component\Console\Question\Question;
2121
use Symfony\Component\Console\Style\SymfonyStyle;
22-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
2322
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
2423
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
2524
use Symfony\Component\Security\Core\User\User;
@@ -33,6 +32,8 @@
3332
*/
3433
class UserPasswordEncoderCommand extends ContainerAwareCommand
3534
{
35+
protected static $defaultName = 'security:encode-password';
36+
3637
private $encoderFactory;
3738
private $userClasses;
3839

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
* file that was distributed with this source code.
2121
*/
2222
use Symfony\Bundle\FrameworkBundle\Console\Application;
23-
use Symfony\Bundle\SecurityBundle\Command\InitAclCommand;
2423
use Symfony\Bundle\SecurityBundle\Command\SetAclCommand;
2524
use Symfony\Component\Console\Tester\CommandTester;
2625
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
@@ -170,7 +169,6 @@ private function getApplication()
170169
$kernel->boot();
171170

172171
$application = new Application($kernel);
173-
$application->add(new InitAclCommand($kernel->getContainer()->get('security.acl.dbal.connection'), $kernel->getContainer()->get('security.acl.dbal.schema')));
174172

175173
$initAclCommand = $application->find('init:acl');
176174
$initAclCommandTester = new CommandTester($initAclCommand);

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CHANGELOG
77
* added `CommandLoaderInterface`, `FactoryCommandLoader` and PSR-11
88
`ContainerCommandLoader` for commands lazy-loading
99
* added a case-insensitive command name matching fallback
10-
* added `DefaultNameProviderInterface`
10+
* added `Command::$defaultName` and `Command::getDefaultName()`
1111

1212
3.3.0
1313
-----

src/Symfony/Component/Console/Command/Command.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
*/
3030
class Command
3131
{
32+
/**
33+
* @var string The name to use by default for calling the Command
34+
*/
35+
protected static $defaultName;
36+
3237
private $application;
3338
private $name;
3439
private $processTitle;
@@ -45,6 +50,17 @@ class Command
4550
private $usages = array();
4651
private $helperSet;
4752

53+
/**
54+
* @return string|null The name to use by default for calling the Command or null when no default name is set
55+
*/
56+
public static function getDefaultName()
57+
{
58+
$class = get_called_class();
59+
$r = new \ReflectionProperty($class, 'defaultName');
60+
61+
return $class === $r->class ? static::$defaultName : null;
62+
}
63+
4864
/**
4965
* Constructor.
5066
*

src/Symfony/Component/Console/Command/DefaultNameProviderInterface.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Console\DependencyInjection;
1313

1414
use Symfony\Component\Console\Command\Command;
15-
use Symfony\Component\Console\Command\DefaultNameProviderInterface;
1615
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
1716
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1817
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
@@ -55,8 +54,9 @@ public function process(ContainerBuilder $container)
5554
}
5655

5756
$commandId = 'console.command.'.strtolower(str_replace('\\', '_', $class));
57+
$commandName = isset($tags[0]['command']) ? $tags[0]['command'] : $class::getDefaultName();
5858

59-
if (!isset($tags[0]['command']) && !$r->implementsInterface(DefaultNameProviderInterface::class)) {
59+
if (!$commandName) {
6060
if (isset($serviceIds[$commandId]) || $container->hasAlias($commandId)) {
6161
$commandId = $commandId.'_'.$id;
6262
}
@@ -70,7 +70,6 @@ public function process(ContainerBuilder $container)
7070
}
7171

7272
$serviceIds[$commandId] = false;
73-
$commandName = isset($tags[0]['command']) ? $tags[0]['command'] : $class::getDefaultName();
7473
unset($tags[0]);
7574
$lazyCommandMap[$commandName] = $id;
7675
$lazyCommandRefs[$id] = new TypedReference($id, $class);

src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Console\Tests\DependencyInjection;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Console\Command\DefaultNameProviderInterface;
1615
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
1716
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
1817
use Symfony\Component\Console\Command\Command;
@@ -180,10 +179,7 @@ class MyCommand extends Command
180179
{
181180
}
182181

183-
class NamedCommand extends Command implements DefaultNameProviderInterface
182+
class NamedCommand extends Command
184183
{
185-
public static function getDefaultName()
186-
{
187-
return 'default';
188-
}
184+
protected static $defaultName = 'default';
189185
}

src/Symfony/Component/Translation/Command/XliffLintCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
class XliffLintCommand extends Command
2828
{
29+
protected static $defaultName = 'lint:xliff';
30+
2931
private $format;
3032
private $displayCorrectFiles;
3133
private $directoryIteratorProvider;

src/Symfony/Component/Yaml/Command/LintCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
class LintCommand extends Command
3030
{
31+
protected static $defaultName = 'lint:yaml';
32+
3133
private $parser;
3234
private $format;
3335
private $displayCorrectFiles;

0 commit comments

Comments
 (0)
0