You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug symfony#61367 [Console] Fix name/alias/usages when an invokable command has an alias (weitzman)
This PR was squashed before being merged into the 7.4 branch.
Discussion
----------
[Console] Fix name/alias/usages when an invokable command has an alias
| Q | A
| ------------- | ---
| Branch? | 7.4
| Bug fix? | yes
| New feature? | no <!-- if yes, also update src/**/CHANGELOG.md -->
| Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md -->
| Issues |
| License | MIT
Invokable commands don't construct their command name properly when an alias is present. This makes the command uncallable. The name has a pipe and alias appended such as `example:name | my-alias`. This appending is done by `#[AsCommand]`. You can see the effect by looking [the test failure in the first commit](https://github.com/symfony/symfony/actions/runs/16842451165/job/47716168358) to this PR.
The PR fixes the issue by removing a `return` when handling of invokables in Command::__construct(). We can mostly use same logic as non-invokables.
I discovered this while moving Drush (Drupal's CLI) to invokable commands.
Commits
-------
c787a07 [Console] Fix name/alias/usages when an invokable command has an alias
if (self::class !== (new \ReflectionMethod($this, 'getDefaultName'))->class) {
119
107
trigger_deprecation('symfony/console', '7.3', 'Overriding "Command::getDefaultName()" in "%s" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', static::class);
@@ -159,7 +147,7 @@ public function __construct(?string $name = null, ?callable $code = null)
159
147
$this->addUsage($usage);
160
148
}
161
149
162
-
if (\is_callable($this) && self::class === (new \ReflectionMethod($this, 'execute'))->getDeclaringClass()->name) {
150
+
if (!$code && \is_callable($this) && self::class === (new \ReflectionMethod($this, 'execute'))->getDeclaringClass()->name) {
0 commit comments