getFilePath(); if (! is_file($filePath)) { throw new ApiException('admin guide file not found'); } $content = file_get_contents($filePath); if ($content === false) { throw new ApiException('failed to read admin guide file'); } return [ 'content' => $content, 'file_path' => 'docs/' . self::GUIDE_FILENAME, 'update_time' => date('Y-m-d H:i:s', filemtime($filePath)), ]; } /** * 保存指南内容到 Markdown 文件 * @param string $content * @return array{content: string, file_path: string, update_time: string} */ public function save(string $content): array { $filePath = $this->getFilePath(); $dir = dirname($filePath); if (! is_dir($dir) && ! mkdir($dir, 0755, true) && ! is_dir($dir)) { throw new ApiException('failed to create docs directory'); } $result = file_put_contents($filePath, $content, LOCK_EX); if ($result === false) { throw new ApiException('failed to save admin guide file'); } clearstatcache(true, $filePath); return [ 'content' => $content, 'file_path' => 'docs/' . self::GUIDE_FILENAME, 'update_time' => date('Y-m-d H:i:s', filemtime($filePath)), ]; } }