thrownewRuntimeException('Signals are not supported. Make sure that the "pcntl" extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.');
* If a Command is not enabled it will not be added.
*
* @param Command[] $commands An array of commands
*/
publicfunctionaddCommands(array$commands):void
{
foreach($commandsas$command){
$this->add($command);
}
}
/**
* 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.
*/
publicfunctionadd(Command$command):?Command
{
$this->init();
$command->setApplication($this);
if(!$command->isEnabled()){
$command->setApplication(null);
returnnull;
}
if(!$commandinstanceofLazyCommand){
// Will throw if the command is not correctly initialized.
$command->getDefinition();
}
if(!$command->getName()){
thrownewLogicException(\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;
}
/**
* Returns a registered command by name or alias.
*
* @throws CommandNotFoundException When given command name does not exist
*/
publicfunctionget(string$name):Command
{
$this->init();
if(!$this->has($name)){
thrownewCommandNotFoundException(\sprintf('The command "%s" does not exist.',$name));
}
// When the command has a different name than the one used at the command loader level
if(!isset($this->commands[$name])){
thrownewCommandNotFoundException(\sprintf('The "%s" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".',$name));
}
$command=$this->commands[$name];
if($this->wantHelps){
$this->wantHelps=false;
$helpCommand=$this->get('help');
$helpCommand->setCommand($command);
return$helpCommand;
}
return$command;
}
/**
* Returns true if the command exists, false otherwise.
thrownewNamespaceNotFoundException(\sprintf("The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s.",$namespace,$this->getAbbreviationSuggestions(array_values($namespaces))),array_values($namespaces));
}
return$exact?$namespace:reset($namespaces);
}
/**
* Finds a command by name or alias.
*
* Contrary to get, this command tries to find the best
* match if you give it an abbreviation of a name or alias.
*
* @throws CommandNotFoundException When command name is incorrect or ambiguous
thrownewCommandNotFoundException(\sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s.",$name,$suggestions),array_values($commands));
}
}
$command=$this->get(reset($commands));
if($command->isHidden()){
thrownewCommandNotFoundException(\sprintf('The command "%s" does not exist.',$name));
}
return$command;
}
/**
* Gets the commands (registered in the given namespace if provided).
*
* The array keys are the full names and the values the command instances.
newInputArgument('command',InputArgument::REQUIRED,'The command to execute'),
newInputOption('--help','-h',InputOption::VALUE_NONE,'Display help for the given command. When no command is given display help for the <info>'.$this->defaultCommand.'</info> command'),
newInputOption('--silent',null,InputOption::VALUE_NONE,'Do not output any message'),
newInputOption('--quiet','-q',InputOption::VALUE_NONE,'Only errors are displayed. All other output is suppressed'),
newInputOption('--verbose','-v|vv|vvv',InputOption::VALUE_NONE,'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
newInputOption('--version','-V',InputOption::VALUE_NONE,'Display this application version'),