PHP中的双重包含预防代码可防止Doxygen生成文档 [英] Double Include Prevention Code in PHP Prevents Doxygen From Generating Documentation
问题描述
我正在编写相对复杂的PHP应用程序,并且具有几个用于类定义的文件,其格式如下:
I am writing relatively complex PHP applications and have several files for class definitions formatted as follows:
<?php
if(!class_exists("FooBar"))
{
/**
* This is documentation for the class FooBar
*/
class FooBar
{
/**
* Documentation for FooBar's constructor
*/
public function __construct() {
;
}
}
} // class_exists
这是为了防止在复杂的类层次结构和应用程序中出现多个定义错误。
This is to prevent multiple definition errors with complex class hierarchies and applications.
但是,Doxygen没有记录用这种方式指定的任何类。注释掉或删除 if(!class_exists())
语句会使Doxygen正确记录此类,但会导致应用程序出错。
However, Doxygen does not document any classes that are specified this way. Commenting out or removing the if(!class_exists())
statement causes Doxygen to correctly document this class, but introduces errors with applications.
有什么方法可以强制Doxygen为这些类生成文档吗?
Is there any way I can force Doxygen to generate documentation for these classes?
推荐答案
如@Sverri所述在评论中,我还认为自动加载是解决问题的好方法(看起来已经做到了)。
As mentioned by @Sverri in the comments, I also think that autoloading is a good way to solve your problem (what it already did, as it seems).
但是对于您(或其他人)正在寻找仅使用Doxygen的解决方案:
But just for the case you (or someone else) is looking for a doxygen-only solution:
您可以使用在doxygen中使用INPUT_FILTERS 可以在创建文档之前删除或更改部分源代码。
You can use INPUT_FILTERS in doxygen to remove or change some parts of the source code before creating the documentation.
您可以使用以下php代码删除包含 if(!class_exists
和花括号 {
}
属于此 if
块的
You can use the following php code to remove all lines containing if(!class_exists
and the braces {
}
that belong to this if
-block, as long as it is not followed by another block.
// input
$source = file_get_contents($argv[1]);
// removes the whole line
list($head,$tail) = preg_split('/.*if\(!class_exists\(.+/', $source, 2);
$openingBracePos = strpos($tail,'{');
$closingBracePos = strrpos($tail,'}');
if($openingBracePos !== false && $closingBracePos !== false)
$source = $head . substr($tail,$openingBracePos+1,
$closingBracePos-$openingBracePos-1);
echo $source;
此过滤器截断
<?php
if(!class_exists("FooBar")) // This comment will also disappear
{
/**
* This is documentation for the class FooBar
*/
class FooBar
{
/**
* Documentation for FooBar\'s constructor
*/
public function __construct() {
;
}
}
} // class_exists
进入
<?php
/**
* This is documentation for the class FooBar
*/
class FooBar
{
/**
* Documentation for FooBar's constructor
*/
public function __construct() {
;
}
}
注意:在Windows上我必须像这样调用过滤器: C:\xampp\php\php.exe php_var_filter.php
Note: On windows I have to call the filter like this: C:\xampp\php\php.exe php_var_filter.php
您可以在 GitHub 上找到更多输入过滤器来改善doxygen的php支持。
You can find some more input filters to improve doxygen's php support on GitHub.
这篇关于PHP中的双重包含预防代码可防止Doxygen生成文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!