From 6e5ad4d140c4056a32466f3ba0ce87d1abf373b2 Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Wed, 26 Nov 2025 17:13:35 +0400 Subject: [PATCH] Fix Console Command Registration (Traits/Interfaces Loading Issue + Missing Translation Support) --- src/App/Adapters/ConsoleAppAdapter.php | 2 ++ src/App/Traits/ConsoleAppTrait.php | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/App/Adapters/ConsoleAppAdapter.php b/src/App/Adapters/ConsoleAppAdapter.php index 0a3a9f375..e38a9e796 100644 --- a/src/App/Adapters/ConsoleAppAdapter.php +++ b/src/App/Adapters/ConsoleAppAdapter.php @@ -85,6 +85,8 @@ public function start(): ?int config()->get('app.version', 'UNKNOWN') ); + $this->loadLanguage(); + $this->registerCoreCommands(); $this->registerAppCommands(); diff --git a/src/App/Traits/ConsoleAppTrait.php b/src/App/Traits/ConsoleAppTrait.php index da1370950..2cddd61c4 100644 --- a/src/App/Traits/ConsoleAppTrait.php +++ b/src/App/Traits/ConsoleAppTrait.php @@ -9,14 +9,16 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\App\Traits; use Symfony\Component\Console\Application; use Quantum\Console\QtCommand; -use Mockery\Exception; +use ReflectionException; +use ReflectionClass; +use Exception; /** * Class ConsoleAppTrait @@ -37,6 +39,7 @@ public function createApplication(string $name, string $version): Application /** * @return void + * @throws ReflectionException */ private function registerCoreCommands() { @@ -48,6 +51,7 @@ private function registerCoreCommands() /** * @return void + * @throws ReflectionException */ private function registerAppCommands() { @@ -61,22 +65,32 @@ private function registerAppCommands() * @param string $directory * @param string $namespace * @return void + * @throws ReflectionException */ private function registerCommands(string $directory, string $namespace) { foreach (get_directory_classes($directory) as $className) { $commandClass = $namespace . $className; - $command = new $commandClass(); + if (!class_exists($commandClass)) { + continue; + } + + $commandReflection = new ReflectionClass($commandClass); + + if (!$commandReflection->isInstantiable()) { + continue; + } - if ($command instanceof QtCommand) { - $this->application->add($command); + if ($commandReflection->isSubclassOf(QtCommand::class)) { + $this->application->add($commandReflection->newInstance()); } } } /** * @return void + * @throws Exception */ private function validateCommand(): void {