This commit is contained in:
lisida 2019-02-14 17:38:23 +08:00
parent a454dfd560
commit a22de36f47
2 changed files with 52 additions and 3 deletions

View File

@ -25,6 +25,11 @@ class ApiDoc
* @var array - 结构化的数组 * @var array - 结构化的数组
*/ */
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;
}
} }

View File

@ -234,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, []))}