From f4503b60f7eb69d4e930cdfbb98c71495f148c05 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 6 May 2025 14:46:13 +0800 Subject: [PATCH] [Console] Run `InvokableCommand` via `execute()` method. --- src/Symfony/Component/Console/Command/Command.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index f79475d56be73..64ea12e5a956b 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -214,12 +214,16 @@ protected function configure() * * @return int 0 if everything went fine, or an exit code * - * @throws LogicException When this abstract method is not implemented + * @throws LogicException When this abstract method is not implemented or doesn't implement InvokableCommand * * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output): int { + if ($this->code) { + return ($this->code)($input, $output); + } + throw new LogicException('You must override the execute() method in the concrete command class.'); } @@ -311,10 +315,6 @@ public function run(InputInterface $input, OutputInterface $output): int $input->validate(); - if ($this->code) { - return ($this->code)($input, $output); - } - return $this->execute($input, $output); }