function Application::add
Adds a command object.
If a command with the same name already exists, it will be overridden. If the command is not enabled it will not be added.
5 calls to Application::add()
- Application::addCommands in vendor/
symfony/ console/ Application.php - Adds an array of command objects.
- Application::doRun in vendor/
composer/ composer/ src/ Composer/ Console/ Application.php - Runs the current application.
- Application::has in vendor/
symfony/ console/ Application.php - Returns true if the command exists, false otherwise.
- Application::init in vendor/
symfony/ console/ Application.php - Application::register in vendor/
symfony/ console/ Application.php - Registers a new command.
File
-
vendor/
symfony/ console/ Application.php, line 539
Class
- Application
- An Application is the container for a collection of commands.
Namespace
Symfony\Component\ConsoleCode
public function add(Command $command) : ?Command {
$this->init();
$command->setApplication($this);
if (!$command->isEnabled()) {
$command->setApplication(null);
return null;
}
if (!$command instanceof LazyCommand) {
// 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_debug_type($command)));
}
$this->commands[$command->getName()] = $command;
foreach ($command->getAliases() as $alias) {
$this->commands[$alias] = $command;
}
return $command;
}