Doxygen:如何在php中描述类成员变量? [英] Doxygen: how to describe class member variables in php?
问题描述
我正在尝试使用doxygen将php代码解析为xml输出. Doxygen不会解析类成员变量的描述.
这是我的示例php文件:
<?php
class A
{
/**
* Id on page.
*
* @var integer
*/
var $id = 1;
}
?>
请注意,注释具有简短说明和变量类型. 这是我从此来源获得的xml:
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.7.2">
<compounddef id="class_a" kind="class" prot="public">
<compoundname>A</compoundname>
<sectiondef kind="public-attrib">
<memberdef kind="variable" id="class_a_1ae97941710d863131c700f069b109991e" prot="public" static="no" mutable="no">
<type></type>
<definition>$id</definition>
<argsstring></argsstring>
<name>$id</name>
<initializer> 1</initializer>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="C:/projects/version6-7/asprunner/PHP/source/classes/a.php" line="11" bodyfile="C:/projects/version6-7/asprunner/PHP/source/classes/a.php" bodystart="11" bodyend="-1"/>
</memberdef>
</sectiondef>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<location file="C:/projects/version6-7/asprunner/PHP/source/classes/a.php" line="5" bodyfile="C:/projects/version6-7/asprunner/PHP/source/classes/a.php" bodystart="4" bodyend="12"/>
<listofallmembers>
<member refid="class_a_1ae97941710d863131c700f069b109991e" prot="public" virt="non-virtual"><scope>A</scope><name>$id</name></member>
</listofallmembers>
</compounddef>
</doxygen>
没有解析描述或类型. 我该如何解决?
我正在使用输入过滤器从带有变量声明的内联@var注释中插入typehints,并删除@var注释,因为它在Doxygen中具有不同的含义.有关更多信息,请参见bug #626105 .
由于Doxygen使用类似C的解析器,因此当运行输入过滤器时,它可以识别类型.
<?php
$source = file_get_contents($argv[1]);
$regexp = '#\@var\s+([^\s]+)([^/]+)/\s+(var|public|protected|private)\s+(\$[^\s;=]+)#';
$replac = '${2} */ ${3} ${1} ${4}';
$source = preg_replace($regexp, $replac, $source);
echo $source;
这是快速破解,并且可能存在错误,它仅适用于我的代码:>
您可以使用Doxy文件中的 INPUT_FILTER 选项启用输入过滤器.将上面的代码保存到名为php_var_filter.php的文件中,并将过滤器值设置为"php php_var_filter.php".
I'm trying to use doxygen to parse php code into xml output. Doxygen does not parse description of class member variables.
Here is my sample php file:
<?php
class A
{
/**
* Id on page.
*
* @var integer
*/
var $id = 1;
}
?>
Note that comment has a brief description and variable type. Here is xml i got from this source:
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.7.2">
<compounddef id="class_a" kind="class" prot="public">
<compoundname>A</compoundname>
<sectiondef kind="public-attrib">
<memberdef kind="variable" id="class_a_1ae97941710d863131c700f069b109991e" prot="public" static="no" mutable="no">
<type></type>
<definition>$id</definition>
<argsstring></argsstring>
<name>$id</name>
<initializer> 1</initializer>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="C:/projects/version6-7/asprunner/PHP/source/classes/a.php" line="11" bodyfile="C:/projects/version6-7/asprunner/PHP/source/classes/a.php" bodystart="11" bodyend="-1"/>
</memberdef>
</sectiondef>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<location file="C:/projects/version6-7/asprunner/PHP/source/classes/a.php" line="5" bodyfile="C:/projects/version6-7/asprunner/PHP/source/classes/a.php" bodystart="4" bodyend="12"/>
<listofallmembers>
<member refid="class_a_1ae97941710d863131c700f069b109991e" prot="public" virt="non-virtual"><scope>A</scope><name>$id</name></member>
</listofallmembers>
</compounddef>
</doxygen>
Neither description or type were parsed. How can I fix this?
I am using an input filter to insert typehints from the @var annotation inline with variable declaration, and remove the @var annotation as it has different meaning in Doxygen. For more info, see bug #626105.
As Doxygen uses C-like parser, when the input filter is run it can recognize types.
<?php
$source = file_get_contents($argv[1]);
$regexp = '#\@var\s+([^\s]+)([^/]+)/\s+(var|public|protected|private)\s+(\$[^\s;=]+)#';
$replac = '${2} */ ${3} ${1} ${4}';
$source = preg_replace($regexp, $replac, $source);
echo $source;
This is a quick hack, and probably have bugs, it just works for my code:
You can enable input filter with INPUT_FILTER option in your Doxyfile. Save the code above to file named php_var_filter.php and set the filter value to "php php_var_filter.php".
这篇关于Doxygen:如何在php中描述类成员变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!