Skip to content

Commit 59ad6c2

Browse files
[Console] allow Command::getName() to return null
1 parent 593ec61 commit 59ad6c2

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
2222
use Symfony\Component\Console\Exception\CommandNotFoundException;
2323
use Symfony\Component\Console\Exception\ExceptionInterface;
24+
use Symfony\Component\Console\Exception\LogicException;
2425
use Symfony\Component\Console\Formatter\OutputFormatter;
2526
use Symfony\Component\Console\Helper\DebugFormatterHelper;
2627
use Symfony\Component\Console\Helper\FormatterHelper;
@@ -459,6 +460,10 @@ public function add(Command $command)
459460
// Will throw if the command is not correctly initialized.
460461
$command->getDefinition();
461462

463+
if (!$command->getName()) {
464+
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($command)));
465+
}
466+
462467
$this->commands[$command->getName()] = $command;
463468

464469
foreach ($command->getAliases() as $alias) {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,10 @@ public function setProcessTitle($title)
453453
/**
454454
* Returns the command name.
455455
*
456-
* @return string The command name
456+
* @return string|null
457457
*/
458458
public function getName()
459459
{
460-
if (!$this->name) {
461-
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($this)));
462-
}
463-
464460
return $this->name;
465461
}
466462

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy