Compare commits
10 Commits
accce45377
...
6ba37efae5
Author | SHA1 | Date | |
---|---|---|---|
|
6ba37efae5 | ||
|
239a492431 | ||
|
5d9fe1d479 | ||
|
a22de36f47 | ||
|
a454dfd560 | ||
|
79ac71cf09 | ||
|
fc38f9c662 | ||
|
4c9fb436d8 | ||
|
9417bffbcf | ||
|
b7134ca2cf |
16
README.md
16
README.md
|
@ -1,20 +1,22 @@
|
||||||
# Api-Doc-PHP
|
# Api-Doc-PHP
|
||||||
|
|
||||||
|
### 主要功能:
|
||||||
|
|
||||||
|
+ 根据接口注释自动生成接口文档
|
||||||
|
|
||||||
|
### 演示地址
|
||||||
|
|
||||||
|
[【Gitee Pages:】http://itxq.gitee.io/api-doc-php](http://itxq.gitee.io/api-doc-php)
|
||||||
|
|
||||||
### 开源地址:
|
### 开源地址:
|
||||||
|
|
||||||
[【GigHub:】https://github.com/itxq/api-doc-php](https://github.com/itxq/api-doc-php)
|
[【GigHub:】https://github.com/itxq/api-doc-php](https://github.com/itxq/api-doc-php)
|
||||||
|
|
||||||
[【码云:】https://gitee.com/itxq/api-doc-php](https://github.com/itxq/api-doc-php)
|
[【码云:】https://gitee.com/itxq/api-doc-php](https://github.com/itxq/api-doc-php)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 主要功能:
|
|
||||||
|
|
||||||
+ 根据接口注释自动生成接口文档
|
|
||||||
|
|
||||||
### 扩展安装:
|
### 扩展安装:
|
||||||
|
|
||||||
+ 方法一:composer命令 `composer require itxq/wechat-sdk-php`
|
+ 方法一:composer命令 `composer require itxq/api-doc-php`
|
||||||
|
|
||||||
+ 方法二:直接下载压缩包,然后进入项目中执行 composer命令 `composer update` 来生成自动加载文件
|
+ 方法二:直接下载压缩包,然后进入项目中执行 composer命令 `composer update` 来生成自动加载文件
|
||||||
|
|
||||||
|
|
193
assets/index.html
Normal file
193
assets/index.html
Normal file
File diff suppressed because one or more lines are too long
|
@ -26,6 +26,11 @@ class ApiDoc
|
||||||
*/
|
*/
|
||||||
private $ApiTree = [];
|
private $ApiTree = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array - 结构化的数组
|
||||||
|
*/
|
||||||
|
private $DocTree = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array - 要生成API的Class类名
|
* @var array - 要生成API的Class类名
|
||||||
*/
|
*/
|
||||||
|
@ -123,4 +128,51 @@ class ApiDoc
|
||||||
}
|
}
|
||||||
return $comments;
|
return $comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function _getActionCommentTmp($class, $type = \ReflectionMethod::IS_PUBLIC) {
|
||||||
|
try {
|
||||||
|
$reflection = new \ReflectionClass($class);
|
||||||
|
//只允许生成public方法
|
||||||
|
$method = $reflection->getMethods($type);
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$comments = [];
|
||||||
|
foreach ($method as $key => $action) {
|
||||||
|
try {
|
||||||
|
$parse = new ParseComment();
|
||||||
|
$actionComments = $parse->parseCommentToArray($action->getDocComment());
|
||||||
|
if (count($actionComments) >= 1 && !in_array($action->name, $this->filterMethod)) {
|
||||||
|
$comments[$actionComments['url']] = [
|
||||||
|
'param' => $actionComments['param'],
|
||||||
|
'code' => $actionComments['code'],
|
||||||
|
'return' => $actionComments['return'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取API文档数据
|
||||||
|
* @param int $type - 方法过滤,默认只获取 public类型 方法
|
||||||
|
* ReflectionMethod::IS_STATIC
|
||||||
|
* ReflectionMethod::IS_PUBLIC
|
||||||
|
* ReflectionMethod::IS_PROTECTED
|
||||||
|
* ReflectionMethod::IS_PRIVATE
|
||||||
|
* ReflectionMethod::IS_ABSTRACT
|
||||||
|
* ReflectionMethod::IS_FINAL
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getApiDocTmp($type = \ReflectionMethod::IS_PUBLIC) {
|
||||||
|
foreach ($this->class as $classItem) {
|
||||||
|
$this->DocTree = array_merge($this->DocTree,$this->_getActionCommentTmp($classItem, $type));
|
||||||
|
}
|
||||||
|
return $this->DocTree;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -52,6 +52,7 @@ class BootstrapApiDoc extends ApiDoc
|
||||||
.action-item .action-title {text-indent: 0.6em;border-left: 3px solid #F0AD4E;font-size: 20px;margin: 8px 0;}
|
.action-item .action-title {text-indent: 0.6em;border-left: 3px solid #F0AD4E;font-size: 20px;margin: 8px 0;}
|
||||||
.table-item {background-color:#FFFFFF;padding-top: 10px;margin-bottom:10px;border: solid 1px #ccc;border-radius: 5px;}
|
.table-item {background-color:#FFFFFF;padding-top: 10px;margin-bottom:10px;border: solid 1px #ccc;border-radius: 5px;}
|
||||||
.list-group-item-sub{padding: .5rem 1.25rem;}
|
.list-group-item-sub{padding: .5rem 1.25rem;}
|
||||||
|
.copyright-content{margin: 10px 0;}
|
||||||
</style>';
|
</style>';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,8 +136,8 @@ class BootstrapApiDoc extends ApiDoc
|
||||||
<div class="col-lg-12">{$this->_getDocList($data)}</div>
|
<div class="col-lg-12">{$this->_getDocList($data)}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12 text-center">
|
<div class="col-lg-12 text-center copyright-content">
|
||||||
版权的撒打算
|
Copyright 2016 - 2018 <a href="http://www.xqitw.cn">小强IT屋</a> 版权所有
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -233,9 +234,6 @@ EXT;
|
||||||
$html = <<<EXT
|
$html = <<<EXT
|
||||||
<div class="list-group-item list-group-item-action action-item col-md-12" id="{$className}_{$actionName}">
|
<div class="list-group-item list-group-item-action action-item col-md-12" id="{$className}_{$actionName}">
|
||||||
<h4 class="action-title">API - {$actionItem['title']}</h4>
|
<h4 class="action-title">API - {$actionItem['title']}</h4>
|
||||||
<p>请求方式:
|
|
||||||
<span class="btn btn-info btn-sm">{$actionItem['method']}</span>
|
|
||||||
</p>
|
|
||||||
<p>请求地址:<a href="{$actionItem['url']}">{$actionItem['url']}</a></p>
|
<p>请求地址:<a href="{$actionItem['url']}">{$actionItem['url']}</a></p>
|
||||||
{$this->_getParamData(Tools::getSubValue('param', $actionItem, []))}
|
{$this->_getParamData(Tools::getSubValue('param', $actionItem, []))}
|
||||||
{$this->_getReturnData(Tools::getSubValue('return', $actionItem, []))}
|
{$this->_getReturnData(Tools::getSubValue('return', $actionItem, []))}
|
||||||
|
@ -305,7 +303,9 @@ EXT;
|
||||||
}
|
}
|
||||||
$html .= '</div></li>';
|
$html .= '</div></li>';
|
||||||
}
|
}
|
||||||
$html .= ' <li class="nav-item"><a class="nav-link" href="?download=api_doc_php">下载文档</a></li>';
|
if (!isset($_GET['download']) || $_GET['download'] !== 'api_doc_php') {
|
||||||
|
$html .= ' <li class="nav-item"><a class="nav-link" href="?download=api_doc_php">下载文档</a></li>';
|
||||||
|
}
|
||||||
$html .= '</ul>';
|
$html .= '</ul>';
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class ParseLine
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function parseLineTitle($line) {
|
public function parseLineTitle($line) {
|
||||||
return ['type' => $line[0], 'content' => $line[1]];
|
return ['type' => isset($line[0]) ? $line[0] : '', 'content' => isset($line[1]) ? $line[1] : ''];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,12 +35,12 @@ class ParseLine
|
||||||
*/
|
*/
|
||||||
public function parseLineParam($line) {
|
public function parseLineParam($line) {
|
||||||
return [
|
return [
|
||||||
'type' => $line[0],
|
'type' => isset($line[0]) ? $line[0] : '',
|
||||||
'param_type' => $line[1],
|
'param_type' => isset($line[1]) ? $line[1] : '',
|
||||||
'param_name' => $line[2],
|
'param_name' => isset($line[2]) ? $line[2] : '',
|
||||||
'param_title' => $line[3],
|
'param_title' => isset($line[3]) ? $line[3] : '',
|
||||||
'param_default' => $line[4],
|
'param_default' => isset($line[4]) ? $line[4] : '',
|
||||||
'param_require' => $line[5],
|
'param_require' => isset($line[5]) ? $line[5] : '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ class ParseLine
|
||||||
*/
|
*/
|
||||||
public function parseLineCode($line) {
|
public function parseLineCode($line) {
|
||||||
return [
|
return [
|
||||||
'type' => $line[0],
|
'type' => isset($line[0]) ? $line[0] : '',
|
||||||
'code' => $line[1],
|
'code' => isset($line[1]) ? $line[1] : '',
|
||||||
'content' => isset($line[2]) ? $line[2] : '',
|
'content' => isset($line[2]) ? $line[2] : '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,9 @@ class ParseLine
|
||||||
*/
|
*/
|
||||||
public function parseLineReturn($line) {
|
public function parseLineReturn($line) {
|
||||||
return [
|
return [
|
||||||
'type' => $line[0],
|
'type' => isset($line[0]) ? $line[0] : '',
|
||||||
'return_type' => $line[1],
|
'return_type' => isset($line[1]) ? $line[1] : '',
|
||||||
'return_name' => $line[2],
|
'return_name' => isset($line[2]) ? $line[2] : '',
|
||||||
'return_title' => isset($line[3]) ? $line[3] : '',
|
'return_title' => isset($line[3]) ? $line[3] : '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user