当前位置: 首页>>代码示例>>PHP>>正文


PHP ApiResult::getResultData方法代码示例

本文整理汇总了PHP中ApiResult::getResultData方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiResult::getResultData方法的具体用法?PHP ApiResult::getResultData怎么用?PHP ApiResult::getResultData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApiResult的用法示例。


在下文中一共展示了ApiResult::getResultData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testErrorFormatterBC

 /**
  * @covers ApiErrorFormatter_BackCompat
  */
 public function testErrorFormatterBC()
 {
     $mainpagePlain = wfMessage('mainpage')->useDatabase(false)->plain();
     $parensPlain = wfMessage('parentheses', 'foobar')->useDatabase(false)->plain();
     $result = new ApiResult(8388608);
     $formatter = new ApiErrorFormatter_BackCompat($result);
     $formatter->addWarning('string', 'mainpage');
     $formatter->addError('err', 'mainpage');
     $this->assertSame(array('error' => array('code' => 'mainpage', 'info' => $mainpagePlain), 'warnings' => array('string' => array('warnings' => $mainpagePlain, ApiResult::META_CONTENT => 'warnings')), ApiResult::META_TYPE => 'assoc'), $result->getResultData(), 'Simple test');
     $result->reset();
     $formatter->addWarning('foo', 'mainpage');
     $formatter->addWarning('foo', 'mainpage');
     $formatter->addWarning('foo', array('parentheses', 'foobar'));
     $msg1 = wfMessage('mainpage');
     $formatter->addWarning('message', $msg1);
     $msg2 = new ApiMessage('mainpage', 'overriddenCode', array('overriddenData' => true));
     $formatter->addWarning('messageWithData', $msg2);
     $formatter->addError('errWithData', $msg2);
     $this->assertSame(array('error' => array('code' => 'overriddenCode', 'info' => $mainpagePlain, 'overriddenData' => true), 'warnings' => array('messageWithData' => array('warnings' => $mainpagePlain, ApiResult::META_CONTENT => 'warnings'), 'message' => array('warnings' => $mainpagePlain, ApiResult::META_CONTENT => 'warnings'), 'foo' => array('warnings' => "{$mainpagePlain}\n{$parensPlain}", ApiResult::META_CONTENT => 'warnings')), ApiResult::META_TYPE => 'assoc'), $result->getResultData(), 'Complex test');
     $result->reset();
     $status = Status::newGood();
     $status->warning('mainpage');
     $status->warning('parentheses', 'foobar');
     $status->warning($msg1);
     $status->warning($msg2);
     $status->error('mainpage');
     $status->error('parentheses', 'foobar');
     $formatter->addMessagesFromStatus('status', $status);
     $this->assertSame(array('error' => array('code' => 'parentheses', 'info' => $parensPlain), 'warnings' => array('status' => array('warnings' => "{$mainpagePlain}\n{$parensPlain}", ApiResult::META_CONTENT => 'warnings')), ApiResult::META_TYPE => 'assoc'), $result->getResultData(), 'Status test');
     $I = ApiResult::META_INDEXED_TAG_NAME;
     $this->assertSame(array(array('type' => 'error', 'message' => 'mainpage', 'params' => array($I => 'param')), array('type' => 'error', 'message' => 'parentheses', 'params' => array('foobar', $I => 'param')), $I => 'error'), $formatter->arrayFromStatus($status, 'error'), 'arrayFromStatus test for error');
     $this->assertSame(array(array('type' => 'warning', 'message' => 'mainpage', 'params' => array($I => 'param')), array('type' => 'warning', 'message' => 'parentheses', 'params' => array('foobar', $I => 'param')), array('message' => 'mainpage', 'params' => array($I => 'param'), 'type' => 'warning'), array('message' => 'mainpage', 'params' => array($I => 'param'), 'type' => 'warning'), $I => 'warning'), $formatter->arrayFromStatus($status, 'warning'), 'arrayFromStatus test for warning');
 }
开发者ID:foxlog,项目名称:wiki,代码行数:36,代码来源:ApiErrorFormatterTest.php

示例2: addWarningOrError

 /**
  * Actually add the warning or error to the result
  * @param string $tag 'warning' or 'error'
  * @param string $moduleName
  * @param ApiMessage|ApiRawMessage $msg
  */
 protected function addWarningOrError($tag, $moduleName, $msg)
 {
     $value = ['code' => $msg->getApiCode()];
     switch ($this->format) {
         case 'wikitext':
             $value += ['text' => $msg->text(), ApiResult::META_CONTENT => 'text'];
             break;
         case 'html':
             $value += ['html' => $msg->parse(), ApiResult::META_CONTENT => 'html'];
             break;
         case 'raw':
             $value += ['message' => $msg->getKey(), 'params' => $msg->getParams()];
             ApiResult::setIndexedTagName($value['params'], 'param');
             break;
         case 'none':
             break;
     }
     $value += $msg->getApiData();
     $path = [$tag . 's', $moduleName];
     $existing = $this->result->getResultData($path);
     if ($existing === null || !in_array($value, $existing)) {
         $flags = ApiResult::NO_SIZE_CHECK;
         if ($existing === null) {
             $flags |= ApiResult::ADD_ON_TOP;
         }
         $this->result->addValue($path, null, $value, $flags);
         $this->result->addIndexedTagName($path, $tag);
     }
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:35,代码来源:ApiErrorFormatter.php

示例3: testDeprecatedContinuation

 /**
  * @covers ApiResult
  */
 public function testDeprecatedContinuation()
 {
     // Ignore ApiResult deprecation warnings during this test
     set_error_handler(function ($errno, $errstr) use(&$warnings) {
         if (preg_match('/Use of ApiResult::\\S+ was deprecated in MediaWiki \\d+.\\d+\\./', $errstr)) {
             return true;
         }
         return false;
     });
     $reset = new ScopedCallback('restore_error_handler');
     $allModules = array(new MockApiQueryBase('mock1'), new MockApiQueryBase('mock2'), new MockApiQueryBase('mocklist'));
     $generator = new MockApiQueryBase('generator');
     $main = new ApiMain(RequestContext::getMain());
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[0], 'm1continue', array(1, 2));
     $result->setContinueParam($allModules[2], 'mlcontinue', 2);
     $result->setGeneratorContinueParam($generator, 'gcontinue', 3);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('mlcontinue' => 2, 'm1continue' => '1|2', 'continue' => '||mock2'), $result->getResultData('continue'));
     $this->assertSame(null, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mock1' => array('m1continue' => '1|2'), 'mocklist' => array('mlcontinue' => 2), 'generator' => array('gcontinue' => 3)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[0], 'm1continue', array(1, 2));
     $result->setGeneratorContinueParam($generator, 'gcontinue', array(3, 4));
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('m1continue' => '1|2', 'continue' => '||mock2|mocklist'), $result->getResultData('continue'));
     $this->assertSame(null, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mock1' => array('m1continue' => '1|2'), 'generator' => array('gcontinue' => '3|4')), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[2], 'mlcontinue', 2);
     $result->setGeneratorContinueParam($generator, 'gcontinue', 3);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('mlcontinue' => 2, 'gcontinue' => 3, 'continue' => 'gcontinue||'), $result->getResultData('continue'));
     $this->assertSame(true, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mocklist' => array('mlcontinue' => 2), 'generator' => array('gcontinue' => 3)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setGeneratorContinueParam($generator, 'gcontinue', 3);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('gcontinue' => 3, 'continue' => 'gcontinue||mocklist'), $result->getResultData('continue'));
     $this->assertSame(true, $result->getResultData('batchcomplete'));
     $this->assertSame(array('generator' => array('gcontinue' => 3)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[0], 'm1continue', array(1, 2));
     $result->setContinueParam($allModules[2], 'mlcontinue', 2);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('mlcontinue' => 2, 'm1continue' => '1|2', 'continue' => '||mock2'), $result->getResultData('continue'));
     $this->assertSame(null, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mock1' => array('m1continue' => '1|2'), 'mocklist' => array('mlcontinue' => 2)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[0], 'm1continue', array(1, 2));
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('m1continue' => '1|2', 'continue' => '||mock2|mocklist'), $result->getResultData('continue'));
     $this->assertSame(null, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mock1' => array('m1continue' => '1|2')), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[2], 'mlcontinue', 2);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('mlcontinue' => 2, 'continue' => '-||mock1|mock2'), $result->getResultData('continue'));
     $this->assertSame(true, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mocklist' => array('mlcontinue' => 2)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
//.........这里部分代码省略.........
开发者ID:ucfengzhun,项目名称:mediawiki,代码行数:101,代码来源:ApiResultTest.php

示例4: testTransformations

 /**
  * @covers ApiResult
  * @dataProvider provideTransformations
  * @param string $label
  * @param array $input
  * @param array $transforms
  * @param array|Exception $expect
  */
 public function testTransformations($label, $input, $transforms, $expect)
 {
     $result = new ApiResult(false);
     $result->addValue(null, 'test', $input);
     if ($expect instanceof Exception) {
         try {
             $output = $result->getResultData('test', $transforms);
             $this->fail('Expected exception not thrown', $label);
         } catch (Exception $ex) {
             $this->assertEquals($ex, $expect, $label);
         }
     } else {
         $output = $result->getResultData('test', $transforms);
         $this->assertEquals($expect, $output, $label);
     }
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:24,代码来源:ApiResultTest.php


注:本文中的ApiResult::getResultData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。