Manual:ApiResult.php/ar

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:ApiResult.php and the translation is 17% complete.

Other languages:
Deutsch • ‎English • ‎polski • ‎العربية • ‎日本語

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.

There are two special key values that change how XML output is generated:

  • '_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
				),
			)
		);
	}
}

انظر أيضا