【发布时间】:2013-03-03 02:05:33
【问题描述】:
我正在努力编写可读且易于理解的文档来描述传递给函数的数组选项的多树结构。
这是一个示例数组结构。
$arr = [
'fields' => [
'title' => [
'name' => 'Document.title',
'format' => 'string',
'readonly' => true
]
]
];
上面的数组有很多可能的选项,但它被用作理解该结构的函数的参数。
function doSomething(array $arr) { ... }
我想在 PHPDoc 中记录数组的结构,但我不确定正确的方法是什么。
这是我现在拥有的。
/**
* Holds configuration settings for each field in a model.
* Defining the field options
*
* array['fields'] array Defines the feilds to be shown by scaffolding.
* array['fields'][fieldName] array Defines the options for a field, or just enables the field if array is not applied.
* array['fields'][fieldName]['name'] string Overrides the field name (default is the array key)
* array['fields'][fieldName]['model'] string (optional) Overrides the model if the field is a belongsTo assoicated value.
* array['fields'][fieldName]['width'] string Defines the width of the field for paginate views. Examples are "100px" or "auto"
* array['fields'][fieldName]['align'] string Alignment types for paginate views (left, right, center)
* array['fields'][fieldName]['format'] string Formatting options for paginate fields. Options include ('currency','nice','niceShort','timeAgoInWords' or a valid Date() format)
* array['fields'][fieldName]['title'] string Changes the field name shown in views.
* array['fields'][fieldName]['desc'] string The description shown in edit/create views.
* array['fields'][fieldName]['readonly'] boolean True prevents users from changing the value in edit/create forms.
* array['fields'][fieldName]['type'] string Defines the input type used by the Form helper (example 'password')
* array['fields'][fieldName]['options'] array Defines a list of string options for drop down lists.
* array['fields'][fieldName]['editor'] boolean If set to True will show a WYSIWYG editor for this field.
* array['fields'][fieldName]['default'] string The default value for create forms.
*
* @param array $arr (See above)
* @return Object A new editor object.
**/
我的问题是,当生成 HTML 文档时,它的格式不是很好。另外,我不确定上面是否清楚地解释了数组结构。
有其他方法吗?
【问题讨论】:
-
看看这个公认的答案:stackoverflow.com/a/2725073/1983684
-
@ChrisL 谢谢,我认为这也是我应该做的。
-
如果您需要数据结构如此具体,那么数组可能不是正确的数据类型?您是否考虑过使用 DTO 类(基本上只是一个具有一堆属性的类)?
-
你可能想看看Phan union types。