error("命令 {$command_class} 无法加载!反射失败:" . $e->getMessage()); continue; } if ($command_class_ref->isAbstract()) { continue; } // 从 AsCommand 注解中获取命令名称 $attr = $command_class_ref->getAttributes(AsCommand::class); if (count($attr) > 0) { $commands[$attr[0]->getArguments()['name']] = fn () => new $command_class(); } else { logger()->warning("命令 {$command_class} 没有使用 AsCommand 注解,无法被加载"); } } // 命令工厂,用于延迟加载命令 $command_loader = new FactoryCommandLoader($commands); $this->setCommandLoader($command_loader); self::$obj = $this; // 用于标记已经初始化完成 parent::__construct($name, ZM_VERSION); } /** * {@inheritdoc} */ public function run(InputInterface $input = null, OutputInterface $output = null): int { // 注册 bootstrap $options = $input?->getOptions() ?? ServerStartCommand::exportOptionArray(); foreach ($this->bootstrappers as $bootstrapper) { resolve($bootstrapper)->bootstrap($options); } try { return parent::run($input, $output); } catch (\Throwable $e) { echo zm_internal_errcode('E00005') . "{$e->getMessage()} at {$e->getFile()}({$e->getLine()})" . PHP_EOL; exit(1); } } }