コード例 #1
0
 /**
  * @covers ApiResult
  */
 public function testMetadata()
 {
     $arr = array('foo' => array('bar' => array()));
     $result = new ApiResult(8388608);
     $result->addValue(null, 'foo', array('bar' => array()));
     $expect = array('foo' => array('bar' => array(ApiResult::META_INDEXED_TAG_NAME => 'ritn', ApiResult::META_TYPE => 'default'), ApiResult::META_INDEXED_TAG_NAME => 'ritn', ApiResult::META_TYPE => 'default'), ApiResult::META_SUBELEMENTS => array('foo', 'bar'), ApiResult::META_INDEXED_TAG_NAME => 'itn', ApiResult::META_PRESERVE_KEYS => array('foo', 'bar'), ApiResult::META_TYPE => 'array');
     ApiResult::setSubelementsList($arr, 'foo');
     ApiResult::setSubelementsList($arr, array('bar', 'baz'));
     ApiResult::unsetSubelementsList($arr, 'baz');
     ApiResult::setIndexedTagNameRecursive($arr, 'ritn');
     ApiResult::setIndexedTagName($arr, 'itn');
     ApiResult::setPreserveKeysList($arr, 'foo');
     ApiResult::setPreserveKeysList($arr, array('bar', 'baz'));
     ApiResult::unsetPreserveKeysList($arr, 'baz');
     ApiResult::setArrayTypeRecursive($arr, 'default');
     ApiResult::setArrayType($arr, 'array');
     $this->assertSame($expect, $arr);
     $result->addSubelementsList(null, 'foo');
     $result->addSubelementsList(null, array('bar', 'baz'));
     $result->removeSubelementsList(null, 'baz');
     $result->addIndexedTagNameRecursive(null, 'ritn');
     $result->addIndexedTagName(null, 'itn');
     $result->addPreserveKeysList(null, 'foo');
     $result->addPreserveKeysList(null, array('bar', 'baz'));
     $result->removePreserveKeysList(null, 'baz');
     $result->addArrayTypeRecursive(null, 'default');
     $result->addArrayType(null, 'array');
     $this->assertEquals($expect, $result->getResultData());
     $arr = array('foo' => array('bar' => array()));
     $expect = array('foo' => array('bar' => array(ApiResult::META_TYPE => 'kvp', ApiResult::META_KVP_KEY_NAME => 'key'), ApiResult::META_TYPE => 'kvp', ApiResult::META_KVP_KEY_NAME => 'key'), ApiResult::META_TYPE => 'BCkvp', ApiResult::META_KVP_KEY_NAME => 'bc');
     ApiResult::setArrayTypeRecursive($arr, 'kvp', 'key');
     ApiResult::setArrayType($arr, 'BCkvp', 'bc');
     $this->assertSame($expect, $arr);
 }
コード例 #2
0
ファイル: ApiParse.php プロジェクト: huatuoorg/mediawiki
 private function formatLimitReportData($limitReportData)
 {
     $result = array();
     foreach ($limitReportData as $name => $value) {
         $entry = array();
         $entry['name'] = $name;
         if (!is_array($value)) {
             $value = array($value);
         }
         ApiResult::setIndexedTagNameRecursive($value, 'param');
         $entry = array_merge($entry, $value);
         $result[] = $entry;
     }
     return $result;
 }
 /**
  * @param $result ApiResult
  * @param $props array
  * @param $message ThinMessage
  * @return array
  */
 public function extractMessageData($result, $props, $message)
 {
     $data['key'] = $message->key();
     if (isset($props['definition'])) {
         $data['definition'] = $message->definition();
     }
     if (isset($props['translation'])) {
         // Remove !!FUZZY!! from translation if present.
         $translation = $message->translation();
         if ($translation !== null) {
             $translation = str_replace(TRANSLATE_FUZZY, '', $translation);
         }
         $data['translation'] = $translation;
     }
     if (isset($props['tags'])) {
         $data['tags'] = $message->getTags();
         $result->setIndexedTagName($data['tags'], 'tag');
     }
     // BC
     if (isset($props['revision'])) {
         $data['revision'] = $message->getProperty('revision');
     }
     if (isset($props['properties'])) {
         foreach ($message->getPropertyNames() as $prop) {
             $data['properties'][$prop] = $message->getProperty($prop);
             if (defined('ApiResult::META_CONTENT')) {
                 ApiResult::setIndexedTagNameRecursive($data['properties'], 'val');
             } else {
                 $result->setIndexedTagName_recursive($data['properties'], 'val');
             }
         }
     }
     return $data;
 }