public function groupWrite($group, $groupConfig) { $sourceFile = "{$this->configPath}/{$group}.php"; $targetFile = "{$this->configPath}/{$this->environment}/{$group}.php"; if (!$this->files->exists($sourceFile)) { throw new \RuntimeException("Config:{$group} not exisits"); } // 如果是强制写入或者目标文件不存在的情况下, copy if ($this->overwrite || !$this->files->exists($targetFile)) { if (!$this->files->copy($sourceFile, $targetFile)) { throw new \RuntimeException("Copy config:{$group} failed"); } $content = file_get_contents($targetFile); foreach ($groupConfig as $key => $value) { $pattern[] = '%' . strtoupper($key) . '%'; $replacements[] = $value; } $content = str_replace($pattern, $replacements, $content); if (!file_put_contents($targetFile, $content)) { throw new \RuntimeException('Writing config file ' . $group . '... fail.'); } } else { logger::info("Copy config:{$group}, current is not overwrite mode and target file already exists, ignore copy."); } }