configPath)) { throw new InvalidArgumentException("[ConfigGeneration] File invalid: {$this->configPath}"); } // 生成 PHP 配置文件 / Generate the PHP configuration file $this->genPhpConfig(); // 备份/同步配置文件到开发环境 / Copy/sync config file to dev environment $this->copyConfigToTmp(); echo "[ConfigGeneration] PHP config file generated successfully.\n"; } /** * 复制配置文件到开发/临时路径 * Copy the configuration file to the dev/temporary path. */ private function copyConfigToTmp(): void { if ( ! copy($this->configPath, $this->configPathDev)) { throw new RuntimeException("[ConfigGeneration] Failed to copy config to dev path: {$this->configPathDev}"); } } /** * 解析 JSON 并生成对应的 PHP 配置类 * Parse JSON and generate the corresponding PHP configuration class. */ private function genPhpConfig(): void { $configRaw = file_get_contents($this->configPath); if (false === $configRaw || '' === $configRaw) { throw new RuntimeException("[ConfigGeneration] Failed to read or empty config file: {$this->configPath}"); } // 解析 JSON 数据 / Parse JSON data $configData = json_decode($configRaw, true); if (null === $configData && \JSON_ERROR_NONE !== json_last_error()) { throw new RuntimeException('[ConfigGeneration] JSON decode error: ' . json_last_error_msg()); } // 将数组转换为一等 PHP 代码格式 / Export array into clean PHP code format $exportedConfig = var_export($configData, true); $configContent = <<phpConfigPath, $configContent)) { throw new RuntimeException("[ConfigGeneration] Error: cannot write generated content to {$this->phpConfigPath}"); } } }