本文整理汇总了PHP中ApiResult::setElement方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiResult::setElement方法的具体用法?PHP ApiResult::setElement怎么用?PHP ApiResult::setElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiResult
的用法示例。
在下文中一共展示了ApiResult::setElement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setContent
/**
* Adds a content element to an array.
* Use this function instead of hardcoding the '*' element.
* @param array $arr To add the content element to
* @param mixed $value
* @param string $subElemName When present, content element is created
* as a sub item of $arr. Use this parameter to create elements in
* format "<elem>text</elem>" without attributes.
*/
public static function setContent(&$arr, $value, $subElemName = null)
{
if (is_array($value)) {
ApiBase::dieDebug(__METHOD__, 'Bad parameter');
}
if (is_null($subElemName)) {
ApiResult::setElement($arr, '*', $value);
} else {
if (!isset($arr[$subElemName])) {
$arr[$subElemName] = array();
}
ApiResult::setElement($arr[$subElemName], '*', $value);
}
}
示例2: addValue
/**
* Add value to the output data at the given path.
* Path is an indexed array, each element specifing 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 $name is empty, the $value is added as a next list element data[] = $value
*/
public function addValue($path, $name, $value)
{
$data =& $this->getData();
if (!is_null($path)) {
if (is_array($path)) {
foreach ($path as $p) {
if (!isset($data[$p])) {
$data[$p] = array();
}
$data =& $data[$p];
}
} else {
if (!isset($data[$path])) {
$data[$path] = array();
}
$data =& $data[$path];
}
}
if (empty($name)) {
$data[] = $value;
} else {
ApiResult::setElement($data, $name, $value);
}
// Add named element
}
示例3: addValue
/**
* Add value to the output data at the given path.
* Path is an indexed array, each element specifing 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 $name is empty, the $value is added as a next list element data[] = $value
* @return bool True if $value fits in the result, false if not
*/
public function addValue($path, $name, $value)
{
global $wgAPIMaxResultSize;
$data =& $this->mData;
if ($this->mCheckingSize) {
$newsize = $this->mSize + self::size($value);
if ($newsize > $wgAPIMaxResultSize) {
return false;
}
$this->mSize = $newsize;
}
if (!is_null($path)) {
if (is_array($path)) {
foreach ($path as $p) {
if (!isset($data[$p])) {
$data[$p] = array();
}
$data =& $data[$p];
}
} else {
if (!isset($data[$path])) {
$data[$path] = array();
}
$data =& $data[$path];
}
}
if (!$name) {
$data[] = $value;
} else {
ApiResult::setElement($data, $name, $value);
}
// Add named element
return true;
}
示例4: addValue
/**
* Add value to the output data at the given path.
* Path is an indexed array, each element specifing the branch at which to add the new value
* Setting $path to array('a','b','c') is equivalent to data['a']['b']['c'] = $value
*/
public function addValue($path, $name, $value)
{
$data =& $this->getData();
if (isset($path)) {
if (is_array($path)) {
foreach ($path as $p) {
if (!isset($data[$p])) {
$data[$p] = array();
}
$data =& $data[$p];
}
} else {
if (!isset($data[$path])) {
$data[$path] = array();
}
$data =& $data[$path];
}
}
ApiResult::setElement($data, $name, $value);
}