CommandCall : allow command class name as command name

2.x 2.7.1
Julien Rosset 9 months ago
parent ca6db43fed
commit 2f19a89609

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

Loading…
Cancel
Save