Manual:ApiResult.php
MediaWiki ファイル: ApiResult.php | |
---|---|
場所: | includes/api/ |
ソース コード: | master • 1.42.3 • 1.41.4 • 1.39.10 |
クラス: | ApiResult |
The ApiResult class represents the result of the API operations.
It simply wraps a nested array() structure, adding some functions to simplify array's modifications. As various modules execute, they add different pieces of information to this result, structuring it as it will be given to the client.
Each subarray may either be a dictionary - key-value pairs with unique keys, or lists, where the items are added using $data[] = $value
notation.
XML 出力の生成方法を変更する 2 つの特別なキー値があります:
- '_element' - This key sets the tag name for the rest of the elements in the current array. It is only inserted if the formatter returned true for getNeedsRawData()
- '*' - This key has special meaning only to the XML formatter, and is output as is for all others. In XML it becomes the content of the current element.
関数
addValue()
addValue ( $path, $name, $value, $flags = 0 )
Add value to the output data at the given path.
Path can be an indexed array, each element specifying the branch at which to add the new value. Setting $path to array('a','b','c') is equivalent to data['a']['b']['c'] = $value. If $path is null, the value will be inserted at the data root. If $name is empty, the $value is added as a next list element data[] = $value.
例
class ApiFoo extends ApiBase {
public function execute() {
$apiResult = $this->getResult();
$r['result'] = 'Success';
$r['bar'] = 'baz';
$apiResult->addValue( null, $this->getModuleName(), $r );
}
public function getResultProperties() {
return array(
'foo' => array(
'result' => array(
ApiBase::PROP_TYPE => array(
'success',
'warning',
'needtoken'
)
),
'bar' => array(
ApiBase::PROP_TYPE => 'string',
ApiBase::PROP_NULLABLE => true
),
)
);
}
}