mea*_*gar 11 php comments codeigniter phpdoc
是否有一种语法来记录采用单个配置数组的函数,而不是单个参数?
我正在考虑CodeIgniter样式的库,它使用类似于此的机制:
<?php
//
// Library definition
//
class MyLibrary {
var $foo;
var $bar;
var $baz;
// ... and many more vars...
/* Following is how CodeIgniter documents their built-in libraries,
* which is mostly useless. AFAIK they should be specifying a name
* and description for their @param (which they don't) and omitting
* @return for constructors
*/
/**
* @access public
* @param array
* @return void
*/
function MyLibrary($config = array()) {
foreach ($config as $key => $value) {
$this->$key = $value;
}
}
}
//
// Library usage:
//
// Iniitialize our configuration parameters
$config['foo'] = 'test';
$config['bar'] = 4;
$config['baz'] = array('x', 'y', 'z');
$x = new MyLibrary($config);
?>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,是否有一些支持的方式来记录配置数组,而不仅仅是纯粹的文本描述?实际上指定一个@param [type] [name] [desc]允许PHPDoc解析有用值的正确值?
顺便说一句,CodeIgniter实际上只是用上面通过$ config数组传入的值覆盖它自己的值,有效地允许你破坏私有成员.我不是粉丝,但我坚持下去.
Pas*_*TIN 11
我从未见过记录这种情况的任何"好"方式 - 而且我从未见过IDE (如Eclipse PDT)可用于参数暗示的任何东西:-(
我会说" 像你的框架一样 ",但正如你所说,它的作用,在这里,还不够好......
但是,可能快速/排序的可能键可能比没有更好; 有点像这样:
@param array $config [key1=>int, otherKey=>string]
Run Code Online (Sandbox Code Playgroud)
不确定它是如何被phpDocumentor或IDE解释的......但是可能值得一试?
这是顺便说一句,我倾向于避免使用这种传递参数的方式的一个原因 - 至少在方法没有太多(可选)参数的情况下.
| 归档时间: |
|
| 查看次数: |
7007 次 |
| 最近记录: |