kernel->executionRunner()->execute( ExecutionDescriptor::cli(), function () use ($input, $output): int { $container = $this->kernel->container(); $console = new ConsoleApplication('Vallarx Console', Kernel::VERSION); $console->setAutoExit(false); /** @var ModuleManager $moduleManager */ $moduleManager = $container->get(ModuleManager::class); foreach ($moduleManager->list() as $module) { $instance = $module->instance(); if (!$instance instanceof ModuleConsoleInterface) { continue; } foreach ($instance->registerCI() as $commandClass) { $this->registerCommand($console, $container, $commandClass); } } return $console->run($input, $output); } ); } /** * @param class-string $commandClass */ private function registerCommand(ConsoleApplication $console, ContainerInterface $container, string $commandClass): void { if (!class_exists($commandClass)) { throw new \RuntimeException("Command class not found: {$commandClass}"); } $reflection = new \ReflectionClass($commandClass); $attributes = $reflection->getAttributes(AsCommand::class); if ($attributes === []) { throw new \RuntimeException("Command {$commandClass} is missing #[AsCommand]."); } $attribute = $attributes[0]->newInstance(); $console->add(new LazyCommand( $attribute->name, [], $attribute->description ?? '', $attribute->hidden ?? false, static fn() => $container->get($commandClass), )); } }