PHP code example of finntenzor / think-light-doc
1. Go to this page and download the library: Download finntenzor/think-light-doc library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
finntenzor / think-light-doc example snippets php
// 文档文件必须返回一个数组,可以在返回数组前执行其他代码
return [
// 按照规则编写文档描述即可
...
];
php
// 引入LightDoc
use finntenzor\lightdoc\LightDoc;
//
// 指定路由
//
// 第一个参数表示路由组(Group)的组名
// 第二个参数为一个关联数组
// 每一个键值对表示一个版本的文档
// 键名表示这个版本文档的版本号(路由中使用此版本号标识)
// 键值表示这个版本文档的文档文件路径(物理路径,不是url)
//
LightDoc::route('lightdoc', [
//
// 路径中可以使用@表示项目根目录
//
'v1.1.3' => '@/docs/v1_1_3.php',
//
// 它等价于如下代码
//
'v2.0.1' => substr(Env::get('root_path'), 0, -1) . '/docs/v2_0_1.php',
]);
php
use finntenzor\lightdoc\LightDoc;
Route::group('app', function () {
Route::group('api', function () {
// 一些其他路由
});
// 将app/docs注册为文档查看路径
LightDoc::route('docs', [
'v1.1.3' => '@/docs/v1_1_3.php',
'v2.0.1' => '@/docs/v2_0_1.php',
]);
});
php
use finntenzor\lightdoc\LightDoc;
Route::group('app', function () {
Route::group('api', function () {
// 一些其他路由
});
// 将app/docs注册为文档查看路径
LightDoc::route('docs', [
'v1.1.3' => '@/docs/v1_1_3.php',
'v2.0.1' => '@/docs/v2_0_1.php',
])->middleware('MustAdmin'); // 定制为仅管理员可以查看
});