From 051cc4f34d181112ffd3ce43efef5bdf12673684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IT=E5=B0=8F=E5=BC=BAxqitw=2Ecn?= <360237521@qq.com> Date: Tue, 5 Jun 2018 11:30:36 +0800 Subject: [PATCH] =?UTF-8?q?ApiDoc=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ApiDoc.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/ApiDoc.php diff --git a/src/ApiDoc.php b/src/ApiDoc.php new file mode 100644 index 0000000..e6b7c0b --- /dev/null +++ b/src/ApiDoc.php @@ -0,0 +1,71 @@ +getDocComment(); + } catch (\Exception $exception) { + return []; + } + $parse = new ParseComment(); + return $parse->parseCommentToArray($classDocComment); + } + + /** + * 获取指定类下方法的注释 + * @param $class - 类名称(存在命名空间时要完整写入) eg: $class = 'itxq\\apidoc\\ApiDoc'; + * @param $type - 方法过滤,默认只获取 public类型 方法 + * ReflectionMethod::IS_STATIC + * ReflectionMethod::IS_PUBLIC + * ReflectionMethod::IS_PROTECTED + * ReflectionMethod::IS_PRIVATE + * ReflectionMethod::IS_ABSTRACT + * ReflectionMethod::IS_FINAL + * @return array - 返回格式为数组(未获取到注释时返回空数组) + */ + public function getActionComment($class, $type = \ReflectionMethod::IS_PUBLIC) { + try { + $reflection = new \ReflectionClass($class); + //只允许生成public方法 + $method = $reflection->getMethods($type); + } catch (\Exception $exception) { + return []; + } + $comments = []; + $parse = new ParseComment(); + foreach ($method as $action) { + try { + $comments[] = $parse->parseCommentToArray($action->getDocComment()); + } catch (\Exception $exception) { + continue; + } + } + return $comments; + } +} \ No newline at end of file