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 {