PHP code example of sunanzhi / annotateddoc
1. Go to this page and download the library: Download sunanzhi/annotateddoc 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/ */
sunanzhi / annotateddoc example snippets
MorsTiin\AnnotatedDoc\Config;
use MorsTiin\AnnotatedDoc\Template;
// 单例配置获取
$config = Config::getInstance();
// 接口列表左边菜单宽度,可能有些接口命名很长,因此左边宽度做了可调整
$config->leftPadding = '300px';
// 文档标题啊
$config->title = 'API管理文档';
// 考虑到有些项目可能需要一些全局描述性,例如 状态码/请求的规则 等,这里的html文件跟当前文件同级即可
$config->docSpecificationUrl = '/doc/desc.html';
// 文档列表显示 方法名/显示方法描述
$config->switchMethod = true;
// 考虑到每个项目架构不同,因此 requestUrl 可能不一定是目录形式组成,所以提供一个回调函数进行 requestUrl 修改
// 具体实现请自行处理,这里只是展示 requestUrlCallBack 使用方式
$config->requestUrlCallback = function(string $requestUrl) {
$urlArr = explode('/', $requestUrl);
$res = '';
foreach($urlArr as $v) {
if(empty($v)) {
continue;
}
if(strpos($v, 'Controller') !== false) {
$v = strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . '-' . "$2", str_replace('Controller', '', $v)));
} else if(strpos($v, 'action') !== false) {
$v = strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . '-' . "$2", str_replace('action', '', $v)));
}
$res .= '/'.$v;
}
return $res;
};
// 模块信息配置 请根据自己要显示的文档路径文件填写,命名空间一定要填写正确
$config->moduleList = [
['path' => __DIR__.'/../../controllers/api', 'namespace' => 'app\\controllers\\api', 'name' => 'api'],
['path' => __DIR__.'/../../controllers/admin', 'namespace' => 'app\\controllers\\admin', 'name' => 'admin'],
];
echo (new Template())->show();
/**
* @param integer $userId 用户id
* @param string $username 用户名
* @param array $extra 拓展参数
*/
/**
* @changeLog {"author": "[email protected] ", "time": "2020-03-09 11:16:00", "event":"更换文档注释"}
*/
/**
* 我是示例标题,首行默认标题
*
* 这是一段接口描述,如有则正常显示
*
* @requestUrl 我是请求链接,可以不用填写
*
* @post
* @get
* @rank
*
* @table 我是表格标题
* 表头 | 表头
* key1 | value1
* key2 | value2
* key3 | value3
* key4 | value4
*
* @param string $param 我是参数描述
* @param string $param 我是参数描述
*
* @resParam string $param 我是返回参数描述
* @resParam string $param 我是返回参数描述
* @resParam string $param 我是返回参数描述
*
* @return array
*
* @requestExample {
* "key1":"我是请求示例",
* "value1":"我是请求示例"
* }
* @requestExample {
* "key2":"我是请求示例",
* "value2":"我是请求示例"
* }
*
* @returnExample {
* "page": {
* "total": "4",
* "limit": "1",
* "current": "1",
* "lastPage": "4"
* },
* "items": [
* {
* "key1": "我是返回示例"
* },
* {
* "key2": "我是返回示例"
* }
* ]
* }
* @returnExample {
* "page": {
* "total": "4",
* "limit": "1",
* "current": "1",
* "lastPage": "4"
* },
* "items": [
* {
* "key1": "我是返回示例"
* },
* {
* "key2": "我是返回示例"
* }
* ]
* }
*
* @author sunanzhi <[email protected] >
* @since 2020.2.16
* @changeLog {"author": "[email protected] ", "time": "2020.03.09 12:12:12", "event": "接口更换文档"}
* @changeLog {"author": "[email protected] ", "time": "2020.03.10 12:12:12", "event": "接口更换文档"}
* @link https://github.com/sunanzhi/annotatedDoc
* @link https://github.com/sunanzhi/annotatedDoc
*/