CommandCall : allow command class name as command name

master 3.8.3
Julien Rosset 9 months ago
parent ab5cab163e
commit 69418f455f

@ -25,8 +25,8 @@ class CommandCall {
private Arrayy $commandArguments;
/**
* @param string|Command $commandName The new command name
* @param null|Arrayy<string, mixed> $commandArguments The command new arguments
* @param string|class-string<Command>|Command $commandName The new command name
* @param null|Arrayy<string, mixed> $commandArguments The command new arguments
*/
public function __construct (string|Command $commandName, ?Arrayy $commandArguments = null) {
$this->setCommandName($commandName);
@ -70,14 +70,20 @@ class CommandCall {
/**
* Set the command name
*
* @param string|Command $commandName The new command name
* @param string|class-string<Command>|Command $commandName The new command name
*
* @return $this
*/
public function setCommandName (string|Command $commandName): self {
$this->commandName = $commandName instanceof Command
? CliHelper::getCommandNameFromClass($commandName->getApplication(), $commandName::class)
: $commandName;
if ($commandName instanceof Command) {
$this->commandName = CliHelper::getCommandNameFromClass($commandName->getApplication(), $commandName::class);
}
elseif (class_exists($commandName)) {
$this->commandName = CliHelper::getCommandNameFromClass($commandName->getApplication(), $commandName);
}
else {
$this->commandName = $commandName;
}
return $this;
}

Loading…
Cancel
Save