@author Author Name [<[email protected]>] 代码编写人(负责人)
@version xx.xx 当前版本号
@param datatype $v_name[,...] description 函数相关联的参数,含有,...表示可传入不定数量的其他参数
@return datatype description 函数或方法的返回值类型
@var datatype 在类中说明类变量(属性)的类型
@example [path|url] description 举一个例子,以阐释使用方法
@todo description 待完成的工作信息或待解决的问题信息
现在已经通过反射获取到方法的文档注释,要怎么获取文档注释的特定内容,比如我现在要获取所有 @param 的,怎么获取?
1
feiyuanqiu 2016 年 4 月 11 日 我用的是 phpdocumentor 的 reflection-docblock 包
如果你没法用 composer 的话可以看看它的实现参考一下 |
2
feiyuanqiu 2016 年 4 月 11 日 |
3
wesley 2016 年 4 月 11 日 反射 + 正则
|
4
vus520 2016 年 4 月 11 日 还有个办法,不需要依赖,自己 parse
$class = new \ReflectionClass($class); $methods = $class->getMethods(); 获取每个 method 的注释,再正则取 $method->getDocComment(); |
5
zonghua 2016 年 4 月 12 日 via iPhone 这样就能创造 PHP 的装饰器 yu fu
|
6
Kokororin 2016 年 4 月 12 日 |
7
liuyao729 2016 年 4 月 12 日 |
8
zeevin 2016 年 4 月 21 日
function getDocComment($str, $tag = '')
{ if (empty($tag)) { return $str; } $matches = array(); preg_match("/".$tag."(.*)(\\r\\n|\\r|\\n)/U", $str, $matches); if (isset($matches[1])) { return trim($matches[1]); } return ''; } $falg = getDocComment($doc, '@flag'); |