[Console] allow Command::getName() to return null
This commit is contained in:
parent
593ec61f60
commit
59ad6c29d1
@ -21,6 +21,7 @@ use Symfony\Component\Console\Event\ConsoleExceptionEvent;
|
||||
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
|
||||
use Symfony\Component\Console\Exception\CommandNotFoundException;
|
||||
use Symfony\Component\Console\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Console\Exception\LogicException;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\DebugFormatterHelper;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
@ -459,6 +460,10 @@ class Application
|
||||
// Will throw if the command is not correctly initialized.
|
||||
$command->getDefinition();
|
||||
|
||||
if (!$command->getName()) {
|
||||
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($command)));
|
||||
}
|
||||
|
||||
$this->commands[$command->getName()] = $command;
|
||||
|
||||
foreach ($command->getAliases() as $alias) {
|
||||
|
@ -453,14 +453,10 @@ class Command
|
||||
/**
|
||||
* Returns the command name.
|
||||
*
|
||||
* @return string The command name
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
if (!$this->name) {
|
||||
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($this)));
|
||||
}
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user