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


PHP ApiResult::reset方法代码示例

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


在下文中一共展示了ApiResult::reset方法的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: testInstanceDataMethods

 /**
  * @covers ApiResult
  */
 public function testInstanceDataMethods()
 {
     $result = new ApiResult(8388608);
     $result->addValue(null, 'setValue', '1');
     $result->addValue(null, null, 'unnamed 1');
     $result->addValue(null, null, 'unnamed 2');
     $result->addValue(null, 'deleteValue', '2');
     $result->removeValue(null, 'deleteValue');
     $result->addValue(array('a', 'b'), 'deleteValue', '3');
     $result->removeValue(array('a', 'b', 'deleteValue'), null, '3');
     $result->addContentValue(null, 'setContentValue', '3');
     $this->assertSame(array('setValue' => '1', 'unnamed 1', 'unnamed 2', 'a' => array('b' => array()), 'setContentValue' => '3', ApiResult::META_TYPE => 'assoc', ApiResult::META_CONTENT => 'setContentValue'), $result->getResultData());
     $this->assertSame(20, $result->getSize());
     try {
         $result->addValue(null, 'setValue', '99');
         $this->fail('Expected exception not thrown');
     } catch (RuntimeException $ex) {
         $this->assertSame('Attempting to add element setValue=99, existing value is 1', $ex->getMessage(), 'Expected exception');
     }
     try {
         $result->addContentValue(null, 'setContentValue2', '99');
         $this->fail('Expected exception not thrown');
     } catch (RuntimeException $ex) {
         $this->assertSame('Attempting to set content element as setContentValue2 when setContentValue ' . 'is already set as the content element', $ex->getMessage(), 'Expected exception');
     }
     $result->addValue(null, 'setValue', '99', ApiResult::OVERRIDE);
     $this->assertSame('99', $result->getResultData(array('setValue')));
     $result->addContentValue(null, 'setContentValue2', '99', ApiResult::OVERRIDE);
     $this->assertSame('setContentValue2', $result->getResultData(array(ApiResult::META_CONTENT)));
     $result->reset();
     $this->assertSame(array(ApiResult::META_TYPE => 'assoc'), $result->getResultData());
     $this->assertSame(0, $result->getSize());
     $result->addValue(null, 'foo', 1);
     $result->addValue(null, 'bar', 1);
     $result->addValue(null, 'top', '2', ApiResult::ADD_ON_TOP);
     $result->addValue(null, null, '2', ApiResult::ADD_ON_TOP);
     $result->addValue(null, 'bottom', '2');
     $result->addValue(null, 'foo', '2', ApiResult::OVERRIDE);
     $result->addValue(null, 'bar', '2', ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP);
     $this->assertSame(array(0, 'top', 'foo', 'bar', 'bottom', ApiResult::META_TYPE), array_keys($result->getResultData()));
     $result->reset();
     $result->addValue(null, 'foo', array('bar' => 1));
     $result->addValue(array('foo', 'top'), 'x', 2, ApiResult::ADD_ON_TOP);
     $result->addValue(array('foo', 'bottom'), 'x', 2);
     $this->assertSame(array('top', 'bar', 'bottom'), array_keys($result->getResultData(array('foo'))));
     $result->reset();
     $result->addValue(null, 'sub', array('foo' => 1));
     $result->addValue(null, 'sub', array('bar' => 1));
     $this->assertSame(array('sub' => array('foo' => 1, 'bar' => 1), ApiResult::META_TYPE => 'assoc'), $result->getResultData());
     try {
         $result->addValue(null, 'sub', array('foo' => 2, 'baz' => 2));
         $this->fail('Expected exception not thrown');
     } catch (RuntimeException $ex) {
         $this->assertSame('Conflicting keys (foo) when attempting to merge element sub', $ex->getMessage(), 'Expected exception');
     }
     $result->reset();
     $title = Title::newFromText("MediaWiki:Foobar");
     $obj = new stdClass();
     $obj->foo = 1;
     $obj->bar = 2;
     $result->addValue(null, 'title', $title);
     $result->addValue(null, 'obj', $obj);
     $this->assertSame(array('title' => (string) $title, 'obj' => array('foo' => 1, 'bar' => 2, ApiResult::META_TYPE => 'assoc'), ApiResult::META_TYPE => 'assoc'), $result->getResultData());
     $fh = tmpfile();
     try {
         $result->addValue(null, 'file', $fh);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         $result->addValue(null, null, $fh);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         $obj->file = $fh;
         $result->addValue(null, 'sub', $obj);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         $obj->file = $fh;
         $result->addValue(null, null, $obj);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     fclose($fh);
     try {
         $result->addValue(null, 'inf', INF);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add non-finite floats to ApiResult', $ex->getMessage(), 'Expected exception');
     }
//.........这里部分代码省略.........
开发者ID:ucfengzhun,项目名称:mediawiki,代码行数:101,代码来源:ApiResultTest.php

示例3: doExport

 /**
  * @param ApiPageSet $pageSet Pages to be exported
  * @param ApiResult $result Result to output to
  */
 private function doExport($pageSet, $result)
 {
     $exportTitles = array();
     $titles = $pageSet->getGoodTitles();
     if (count($titles)) {
         $user = $this->getUser();
         /** @var $title Title */
         foreach ($titles as $title) {
             if ($title->userCan('read', $user)) {
                 $exportTitles[] = $title;
             }
         }
     }
     $exporter = new WikiExporter($this->getDB());
     // WikiExporter writes to stdout, so catch its
     // output with an ob
     ob_start();
     $exporter->openStream();
     foreach ($exportTitles as $title) {
         $exporter->pageByTitle($title);
     }
     $exporter->closeStream();
     $exportxml = ob_get_contents();
     ob_end_clean();
     // Don't check the size of exported stuff
     // It's not continuable, so it would cause more
     // problems than it'd solve
     if ($this->mParams['exportnowrap']) {
         $result->reset();
         // Raw formatter will handle this
         $result->addValue(null, 'text', $exportxml, ApiResult::NO_SIZE_CHECK);
         $result->addValue(null, 'mime', 'text/xml', ApiResult::NO_SIZE_CHECK);
     } else {
         $r = array();
         ApiResult::setContent($r, $exportxml);
         $result->addValue('query', 'export', $r, ApiResult::NO_SIZE_CHECK);
     }
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:42,代码来源:ApiQuery.php

示例4: doExport

 /**
  * @param ApiPageSet $pageSet Pages to be exported
  * @param ApiResult $result Result to output to
  */
 private function doExport($pageSet, $result)
 {
     $exportTitles = [];
     $titles = $pageSet->getGoodTitles();
     if (count($titles)) {
         $user = $this->getUser();
         /** @var $title Title */
         foreach ($titles as $title) {
             if ($title->userCan('read', $user)) {
                 $exportTitles[] = $title;
             }
         }
     }
     $exporter = new WikiExporter($this->getDB());
     $sink = new DumpStringOutput();
     $exporter->setOutputSink($sink);
     $exporter->openStream();
     foreach ($exportTitles as $title) {
         $exporter->pageByTitle($title);
     }
     $exporter->closeStream();
     // Don't check the size of exported stuff
     // It's not continuable, so it would cause more
     // problems than it'd solve
     if ($this->mParams['exportnowrap']) {
         $result->reset();
         // Raw formatter will handle this
         $result->addValue(null, 'text', $sink, ApiResult::NO_SIZE_CHECK);
         $result->addValue(null, 'mime', 'text/xml', ApiResult::NO_SIZE_CHECK);
     } else {
         $result->addValue('query', 'export', $sink, ApiResult::NO_SIZE_CHECK);
         $result->addValue('query', ApiResult::META_BC_SUBELEMENTS, ['export']);
     }
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:38,代码来源:ApiQuery.php


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