Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f640e6c

Browse files
bug #41686 [Console] Fix using #[AsCommand] without DI (nicolas-grekas)
This PR was merged into the 5.3 branch. Discussion ---------- [Console] Fix using #[AsCommand] without DI | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #41547 | License | MIT | Doc PR | - Commits ------- c4357ea [Console] Fix using #[AsCommand] without DI
2 parents d583b4f + c4357ea commit f640e6c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,18 @@ public function __construct(string $name = null)
101101
{
102102
$this->definition = new InputDefinition();
103103

104-
if (null !== $name || null !== $name = static::getDefaultName()) {
104+
if (null === $name && null !== $name = static::getDefaultName()) {
105+
$aliases = explode('|', $name);
106+
107+
if ('' === $name = array_shift($aliases)) {
108+
$this->setHidden(true);
109+
$name = array_shift($aliases);
110+
}
111+
112+
$this->setAliases($aliases);
113+
}
114+
115+
if (null !== $name) {
105116
$this->setName($name);
106117
}
107118

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@ public function testCommandAttribute()
414414
{
415415
$this->assertSame('|foo|f', Php8Command::getDefaultName());
416416
$this->assertSame('desc', Php8Command::getDefaultDescription());
417+
418+
$command = new Php8Command();
419+
420+
$this->assertSame('foo', $command->getName());
421+
$this->assertSame('desc', $command->getDescription());
422+
$this->assertTrue($command->isHidden());
423+
$this->assertSame(['f'], $command->getAliases());
417424
}
418425
}
419426

0 commit comments

Comments
 (0)