PHP 中有一个好的(独立的)PHPDoc 解析器类或函数吗?
我正在寻找一些转换 PHP Docblock 的方法(用于通过 Doxygen) 到我可以在 PHP 中检查的结构中。
例如,我想解析
/**
* Multiply two values
* @CHECKME
*
* @author someone
* @created eons ago
*
* @param integer $x
* @param integer $x
*
* @return integer
*/
function multiply($x, $y)
{
return $x * $y;
}
为类似的内容:
array(
'author' => 'someone'
,'created' => 'eons ago'
,'param' => array(
'integer $x'
,'integer $y'
)
,'_flags' => array(
'@CHECKME'
)
);
我明确不能使用 PEAR< /a> 或任何此类库,它必须是相对独立的。任何比在剥离注释大纲后使用一堆正则表达式更好的给定解决方案都会很棒。
I'm looking for some method of converting a PHP Docblock (as used for generating documentation by tools like Doxygen) into a structure I can inspect in PHP.
For example, I want to parse
/**
* Multiply two values
* @CHECKME
*
* @author someone
* @created eons ago
*
* @param integer $x
* @param integer $x
*
* @return integer
*/
function multiply($x, $y)
{
return $x * $y;
}
into something similar to:
array(
'author' => 'someone'
,'created' => 'eons ago'
,'param' => array(
'integer $x'
,'integer $y'
)
,'_flags' => array(
'@CHECKME'
)
);
I explicitly cannot use PEAR or any such library, it has to be relatively standalone. Any given solution that is better than using a bunch of regular expressions after stripping away comment outline would be awesome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想知道您是否不能只使用 phpdocumentor 类。他们已经解析了数据。我怀疑您可以编写自己的临时解析器来处理文件,然后以您想要的任何方式处理原始对象。
I wonder if you couldn't just use the phpdocumentor classes. They already parse the data. I suspect you could write your own interim parser to process a file but then handle the raw objects in any way you want.
以 Reflection 类 [1] 作为起点,特别是其 getDocComment() 方法 [2]。此外,Matthew 关于他尝试使用它的博客文章 [3] 可能会提供进一步的见解。
[1] -- http://www.php.net/manual/en/ class.reflectionclass.php
[2] -- http://www .php.net/manual/en/reflectionclass.getdoccomment.php
[3] -- http://mwop.net/blog/125-PHP-5s-Reflection-API
Look at using the Reflection class [1] as a starting point, particularly its getDocComment() method [2]. Also, Matthew's blog post about his foray into using it [3] may provide further insights.
[1] -- http://www.php.net/manual/en/class.reflectionclass.php
[2] -- http://www.php.net/manual/en/reflectionclass.getdoccomment.php
[3] -- http://mwop.net/blog/125-PHP-5s-Reflection-API
PHPDocumentor 是一个独立的文档块解析器。
PHPDocumentor IS a standalone docblock parser.
我编写了一个运行时 PHP 文档实用程序,其中包含 PHPDoc 解析器类(Documentor)。如果您想看一下,我认为这将满足您的要求。如果您有任何改进或错误修复,也可以在 github 上找到它。
I have written a runtime PHP documentation utility that contains a PHPDoc parser class (Doqumentor). I would think this will do what you want if you want to take a look. It is also available on github if you have any improvements or bug fixes.