使用 PHPdoc 记录 PHP 扩展
我用 C 语言编写了一个 PHP 扩展,我想创建 PHPdoc 文档,以便我的用户能够获得调用我的扩展时,他们的 PHP IDE(在本例中为 Netbeans)中包含内联文档。
理想情况下,我想通过将 PHPdocs 嵌入 C 代码中来实现此目的,以将实现和文档放在一起。
假设可以将 PHPdocs 嵌入到 C 语言中,那么需要哪些额外步骤才能使文档出现在 Netbeans 中(就像 PHP 代码的 PHPdocs 一样)?
编辑:
O'Reilly 编程 PHP 指的是 / * {{{ proto
注释格式用于文档生成,但我不确定引用的脚本是否生成 PHPdocs:
不仅使用了 {{{ 原型行 用于在编辑器中折叠,但也是 由 genfunclist 解析并 genfuncsummary 脚本的一部分 PHP 文档项目的一部分。 如果 你永远不会分发你的 延伸并且没有野心 将其与 PHP 捆绑在一起,您可以 删除这些评论。
I've written a PHP extension in C, and I want to create PHPdoc documentation so that my users will get inline docs in their PHP IDE (in this case, Netbeans) when calling my extension.
Ideally I'd like to do this by embedding the PHPdocs in the C code, to keep implementation and documentation together.
Assuming it's possible to embed PHPdocs into the C, what extra steps are needed to make the documentation appear in Netbeans (as it would for PHPdocs of PHP code)?
edit:
O'Reilly Programming PHP refers to the /* {{{ proto
comment format being used in doc generation, though I'm not sure if the referred scripts generate PHPdocs:
The {{{ proto line is not only used
for folding in the editor, but is also
parsed by the genfunclist and
genfuncsummary scripts that are part
of the PHP documentation project. If
you are never going to distribute your
extension and have no ambitions to
have it bundled with PHP, you can
remove these comments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一种有效的方法是使用带有适当 PHPdocs 的存根函数的 PHP 文件,然后不要将其包含在 PHP 应用程序中,但要将其添加到 Netbean 的 PHP 包含路径中(在
File->Project Properties- >PHP 包含路径
)。通过这种方式,类型完成和内联文档可以工作,但 PHP 不会因函数的多个声明而感到困惑。
这看起来有点老套,因为最好将文档与实现放在同一个文件中,但它实际上似乎是正确的方法,因为这就是内置函数和扩展的记录方式 - 请参阅
~/ netbeans-6.7/php1/phpstubs/phpruntime/*.php
例如:
在 C 文件中:
然后在 PHP 文件中,存根声明:
One approach that works is to have a PHP file with stub functions with the appropriate PHPdocs, then DON'T include it in the PHP application, but DO add it to Netbean's PHP include path (in
File->Project Properties->PHP Include Path
).This way type completion and inline docs work, but PHP isn't confused by multiple declarations of the function.
This seems a bit hacky, since it would be good keep the docs in the same file as the implementation, but it does actually seem to the correct approach, since that's how the built in functions and extensions are documented - see
~/netbeans-6.7/php1/phpstubs/phpruntime/*.php
eg:
In the C file:
And then in a PHP file, the stub declaration:
您只需在评论中使用正确的标签即可。
您可以在文档中找到所有可用的标签
PHPDoc
you only need to use the right TAGS inside your Comments.
You can find all available tags on the documenation
PHPDoc
我认为可以使用 Reflection API 来生成原型文件,尽管我找不到完全可以做到这一点的现有代码。
I think it is possible to use Reflection API to generate the prototype file, though I could not find existing code that does exactly that.
正如扩展骨架中所写:
As written in extension skeleton: