我开始使用 Doxygen 来记录我的 PHP 代码。请参阅以下示例:
namespace \MyClasses;
class Order {
/**
* Some Description
*
* @var \MyClasses\Customer $customer
*/
protected $customer;
}
@var
命令呈现为 MyClasses Customer MyClasses\Order::$customer
作为类型而不是 \MyClasses\Customer MyClasses\Order::$customer
这是正确的,保持命名空间不变。有没有办法实现这一目标?放置两个反斜杠 \\MyClasses\\Customer
也不起作用。@param
另一方面似乎适用于命名空间。我使用的是最新版本 1.8.13。配置几乎是默认的。
最佳答案
如果有人仍然遇到这个问题,那么它已在 doxygen 的支持下“解决”了。这是Bugzilla bug_795953 (现在在: https://github.com/doxygen/doxygen/issues/5553 )。
您所要做的(在 PHP 文件中)就是创建/自定义 INPUT_FILTER对于 doxygen 并包含这段代码:
<?php
// Input
$source = file_get_contents($argv[1]);
// removes preceding '\' or '::' for the use of namespaces.
$regexp = '/ \\\\/';
$replace = ' ';
$source = preg_replace($regexp, $replace, $source);
// adds possibility to use '\' for namespaces
$regexp = '/\\\\/';
$replace = '::';
$source = preg_replace($regexp, $replace, $source);
// Output
echo $source;
?>
如果您使用以“@”(@var、@param 等)开头的所有文档“命令”,则此方法有效。如果你不这样做,你必须对正则表达式做一些调整,让它也像这样工作。
doxygen 不识别命名空间的原因是因为 '\' 键被设置为 doxygen 的命令,所以它不能用于代码中的任何其他内容。因此,将所有 '\' 更改为 '::',将使其了解这是一个命名空间引用。
关于php - Doxygen:@var 使用命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45679891/