From a22de36f47a5279a710eb670b47a7a73d2a2669f Mon Sep 17 00:00:00 2001 From: lisida <506400117@qq.com> Date: Thu, 14 Feb 2019 17:38:23 +0800 Subject: [PATCH] test --- src/ApiDoc.php | 52 +++++++++++++++++++++++++++++++++++++++++ src/BootstrapApiDoc.php | 3 --- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/ApiDoc.php b/src/ApiDoc.php index 775b50c..e869292 100644 --- a/src/ApiDoc.php +++ b/src/ApiDoc.php @@ -25,6 +25,11 @@ class ApiDoc * @var array - 结构化的数组 */ 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; + } } \ No newline at end of file diff --git a/src/BootstrapApiDoc.php b/src/BootstrapApiDoc.php index a559f26..57676f2 100644 --- a/src/BootstrapApiDoc.php +++ b/src/BootstrapApiDoc.php @@ -234,9 +234,6 @@ EXT; $html = <<

API - {$actionItem['title']}

-

请求方式: - {$actionItem['method']} -

请求地址:{$actionItem['url']}

{$this->_getParamData(Tools::getSubValue('param', $actionItem, []))} {$this->_getReturnData(Tools::getSubValue('return', $actionItem, []))}