From 2f19a896091a3d8203c5973834bb66a7b501f486 Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Wed, 30 Oct 2024 11:59:44 +0100 Subject: [PATCH] CommandCall : allow command class name as command name --- src/CliProgram/CommandCall/CommandCall.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/CliProgram/CommandCall/CommandCall.php b/src/CliProgram/CommandCall/CommandCall.php index 7b2a72e..f04b3d3 100644 --- a/src/CliProgram/CommandCall/CommandCall.php +++ b/src/CliProgram/CommandCall/CommandCall.php @@ -25,8 +25,8 @@ class CommandCall { private Arrayy $commandArguments; /** - * @param string|Command $commandName The new command name - * @param null|Arrayy $commandArguments The command new arguments + * @param string|class-string|Command $commandName The new command name + * @param null|Arrayy $commandArguments The command new arguments */ public function __construct ($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 $commandName The new command name * * @return $this */ public function setCommandName ($commandName): self { - $this->commandName = $commandName instanceof Command - ? CliHelper::getCommandNameFromClass($commandName->getApplication(), get_class($commandName)) - : $commandName; + if ($commandName instanceof Command) { + $this->commandName = CliHelper::getCommandNameFromClass($commandName->getApplication(), get_class($commandName)); + } + elseif (class_exists($commandName)) { + $this->commandName = CliHelper::getCommandNameFromClass($commandName->getApplication(), $commandName); + } + else { + $this->commandName = $commandName; + } return $this; }