8000 [Console] Fix using #[AsCommand] without DI by nicolas-grekas · Pull Request #41686 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fix using #[AsCommand] without DI #41686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Console] Fix using #[AsCommand] without DI
  • Loading branch information
nicolas-grekas committed Jun 12, 2021
commit c4357ea78070091b2278e1c70ce53257ab035923
13 changes: 12 additions & 1 deletion src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,18 @@ public function __construct(string $name = null)
{
$this->definition = new InputDefinition();

if (null !== $name || null !== $name = static::getDefaultName()) {
if (null === $name && null !== $name = static::getDefaultName()) {
$aliases = explode('|', $name);

if ('' === $name = array_shift($aliases)) {
$this->setHidden(true);
$name = array_shift($aliases);
}

$this->setAliases($aliases);
}

if (null !== $name) {
$this->setName($name);
}

Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Console/Tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ public function testCommandAttribute()
{
$this->assertSame('|foo|f', Php8Command::getDefaultName());
$this->assertSame('desc', Php8Command::getDefaultDescription());

$command = new Php8Command();

$this->assertSame('foo', $command->getName());
$this->assertSame('desc', $command->getDescription());
$this->assertTrue($command->isHidden());
$this->assertSame(['f'], $command->getAliases());
}
}

Expand Down
0