Compare commits

...

10 Commits

Author SHA1 Message Date
董巍
6ba37efae5 Update composer.json 2019-02-19 14:46:36 +08:00
董巍
239a492431 Update composer.json 2019-02-19 14:30:09 +08:00
董巍
5d9fe1d479 Merge branch 'feature/tool_doc' into 'master'
doc

See merge request composer/php-rpc-doc!1
2019-02-15 18:45:18 +08:00
lisida
a22de36f47 test 2019-02-14 17:38:23 +08:00
IT小强xqitw.cn
a454dfd560 去除下载按钮 2018-07-12 15:38:23 +08:00
IT小强xqitw.cn
79ac71cf09
Merge pull request #1 from itxq/v1.1.x-dev
细节优化
2018-06-24 12:20:25 +08:00
IT小强xqitw.cn
fc38f9c662 细节优化 2018-06-24 12:19:11 +08:00
IT小强xqitw.cn
4c9fb436d8 README.md 文件更新 2018-06-07 15:22:08 +08:00
IT小强xqitw.cn
9417bffbcf 演示页面 2018-06-07 15:14:55 +08:00
IT小强xqitw.cn
b7134ca2cf 添加版权 2018-06-07 14:02:05 +08:00
5 changed files with 272 additions and 25 deletions

View File

@ -1,20 +1,22 @@
# 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)
[【码云:】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` 来生成自动加载文件

193
assets/index.html Normal file

File diff suppressed because one or more lines are too long

View File

@ -26,6 +26,11 @@ class ApiDoc
*/
private $ApiTree = [];
/**
* @var array - 结构化的数组
*/
private $DocTree = [];
/**
* @var array - 要生成API的Class类名
*/
@ -123,4 +128,51 @@ class ApiDoc
}
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;
}
}

View File

@ -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;}
.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;}
.copyright-content{margin: 10px 0;}
</style>';
/**
@ -135,8 +136,8 @@ class BootstrapApiDoc extends ApiDoc
<div class="col-lg-12">{$this->_getDocList($data)}</div>
</div>
<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>
@ -233,9 +234,6 @@ EXT;
$html = <<<EXT
<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>
<p>请求方式:
<span class="btn btn-info btn-sm">{$actionItem['method']}</span>
</p>
<p>请求地址:<a href="{$actionItem['url']}">{$actionItem['url']}</a></p>
{$this->_getParamData(Tools::getSubValue('param', $actionItem, []))}
{$this->_getReturnData(Tools::getSubValue('return', $actionItem, []))}
@ -305,7 +303,9 @@ EXT;
}
$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>';
return $html;
}

View File

@ -25,7 +25,7 @@ class ParseLine
* @return array
*/
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) {
return [
'type' => $line[0],
'param_type' => $line[1],
'param_name' => $line[2],
'param_title' => $line[3],
'param_default' => $line[4],
'param_require' => $line[5],
'type' => isset($line[0]) ? $line[0] : '',
'param_type' => isset($line[1]) ? $line[1] : '',
'param_name' => isset($line[2]) ? $line[2] : '',
'param_title' => isset($line[3]) ? $line[3] : '',
'param_default' => isset($line[4]) ? $line[4] : '',
'param_require' => isset($line[5]) ? $line[5] : '',
];
}
@ -51,8 +51,8 @@ class ParseLine
*/
public function parseLineCode($line) {
return [
'type' => $line[0],
'code' => $line[1],
'type' => isset($line[0]) ? $line[0] : '',
'code' => isset($line[1]) ? $line[1] : '',
'content' => isset($line[2]) ? $line[2] : '',
];
}
@ -64,9 +64,9 @@ class ParseLine
*/
public function parseLineReturn($line) {
return [
'type' => $line[0],
'return_type' => $line[1],
'return_name' => $line[2],
'type' => isset($line[0]) ? $line[0] : '',
'return_type' => isset($line[1]) ? $line[1] : '',
'return_name' => isset($line[2]) ? $line[2] : '',
'return_title' => isset($line[3]) ? $line[3] : '',
];
}