Example #1
0
 /**
  * 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);
     }
 }
 /**
  * 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
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * 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);
 }