使用 phpDocumentor 记录类常量组

发布于 2024-12-15 03:25:24 字数 901 浏览 5 评论 0 原文

假设我有一个带有参数的方法,其有效值被声明为类常量(例如 PGSQL_ASSOC/PGSQL_NUM/PGSQL_BOTH) 。还有另一种方法,具有类似的参数,使用另一组类常量。有没有一种方法可以向 phpDocumentor 描述每组常量属于一组逻辑替代项?将它们分组记录并能够引用方法文档中的特定组将很有用。使用文档块模板并不会减少它,因为模板的简短描述被忽略(增加无用的混乱),而模板的长描述被附加到特定于常量的描述,导致某种向后的措辞(例如“BAR_MODE_1 does Foo::bar() 的操作模式”,而不是“Foo::bar() 的操作模式:BAR_MODE_1 执行此操作。”)。

例子:

class Foo {

    // this group of constants are valid modes for the bar() method
    const BAR_MODE_1 = 1;
    const BAR_MODE_2 = 2;
    const BAR_MODE_3 = 3;

    /**
     * @param int see Foo::BAR_MODE_* constants
     */
    public function bar($mode) { ... }

    // this group of constants are valid modes for the baz() method
    const BAZ_MODE_1 = 1;
    const BAZ_MODE_2 = 2;
    const BAZ_MODE_3 = 3;

    /**
     * @param int see Foo::BAZ_MODE_* constants
     */
    public function baz($mode) { ... }

}

Let's say I've got a method that has a parameter, whose valid values are declared as class constants (think PGSQL_ASSOC/PGSQL_NUM/PGSQL_BOTH). And there's another method, with a similar parameter, using another set of class constants. Is there a way to describe to phpDocumentor that each set of constants as belonging to a logical group of alternatives? It would be useful to have them documented in groups, and being able to refer to the specific groups in the method documentation. Using docblock templates doesn't cut it, as the template's short description is ignored (adding useless clutter), while the long description of the template is appended to the constant-specific description, resulting in kind-of backwards wording (e.g. "BAR_MODE_1 does this and that. Operation modes for Foo::bar()", instead of "Operation modes for Foo::bar(): BAR_MODE_1 does this and that.").

Example:

class Foo {

    // this group of constants are valid modes for the bar() method
    const BAR_MODE_1 = 1;
    const BAR_MODE_2 = 2;
    const BAR_MODE_3 = 3;

    /**
     * @param int see Foo::BAR_MODE_* constants
     */
    public function bar($mode) { ... }

    // this group of constants are valid modes for the baz() method
    const BAZ_MODE_1 = 1;
    const BAZ_MODE_2 = 2;
    const BAZ_MODE_3 = 3;

    /**
     * @param int see Foo::BAZ_MODE_* constants
     */
    public function baz($mode) { ... }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

○愚か者の日 2024-12-22 03:25:24

另一种风格可能是使用 PHPDocumentor DocBlock 模板

/**#@+
* This comment applies to each in the block
*
* @var varType 
*/
protected $_var1 = 1;
protected $_var2 = 2;
/**#@-*/

请参阅:http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.docblock

Another style may be to use the PHPDocumentor DocBlock Templates

/**#@+
* This comment applies to each in the block
*
* @var varType 
*/
protected $_var1 = 1;
protected $_var2 = 2;
/**#@-*/

see: http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.docblock

末蓝 2024-12-22 03:25:24

我首先想到的是 @see - 标签,它显示元素文档的链接。

/**
 * @param int 
 * @see Foo::BAR_MODE_* constants
 */
public function bar($mode) { ... }

更多详细信息可以在手册中找到。

First thing which comes to my mind is the @see - Tag, it display a link to the documentation for an element.

/**
 * @param int 
 * @see Foo::BAR_MODE_* constants
 */
public function bar($mode) { ... }

More details can be found here in the manual.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文