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

Appearance settings

Commit 7784b1b

Browse filesBrowse files
nicolas-grekasRobin Chalas
authored and
Robin Chalas
committed
[Console] Add protected static $defaultName to set the default name of a Command
1 parent 5d9ae6b commit 7784b1b
Copy full SHA for 7784b1b

File tree

Expand file treeCollapse file tree

5 files changed

+20
-36
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+20
-36
lines changed

‎src/Symfony/Component/Console/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/CHANGELOG.md
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/Command.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
class Command
3131
{
32+
protected static $defaultName;
33+
3234
private $application;
3335
private $name;
3436
private $processTitle;
@@ -45,6 +47,17 @@ class Command
4547
private $usages = array();
4648
private $helperSet;
4749

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

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/DefaultNameProviderInterface.php
-26Lines changed: 0 additions & 26 deletions
This file was deleted.

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php
+4-3Lines changed: 4 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;
@@ -56,7 +55,7 @@ public function process(ContainerBuilder $container)
5655

5756
$commandId = 'console.command.'.strtolower(str_replace('\\', '_', $class));
5857

59-
if (!isset($tags[0]['command']) && !$r->implementsInterface(DefaultNameProviderInterface::class)) {
58+
if (!isset($tags[0]['command']) && !$commandName = $class::getDefaultName()) {
6059
if (isset($serviceIds[$commandId]) || $container->hasAlias($commandId)) {
6160
$commandId = $commandId.'_'.$id;
6261
}
@@ -70,7 +69,9 @@ public function process(ContainerBuilder $container)
7069
}
7170

7271
$serviceIds[$commandId] = false;
73-
$commandName = isset($tags[0]['command']) ? $tags[0]['command'] : $class::getDefaultName();
72+
if (isset($tags[0]['command'])) {
73+
$commandName = $tags[0]['command'];
74+
}
7475
unset($tags[0]);
7576
$lazyCommandMap[$commandName] = $id;
7677
$lazyCommandRefs[$id] = new TypedReference($id, $class);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php
+2-6Lines 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
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.