本文整理匯總了PHP中ApiMain::getErrorFormatter方法的典型用法代碼示例。如果您正苦於以下問題:PHP ApiMain::getErrorFormatter方法的具體用法?PHP ApiMain::getErrorFormatter怎麽用?PHP ApiMain::getErrorFormatter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ApiMain
的用法示例。
在下文中一共展示了ApiMain::getErrorFormatter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testDeprecatedFunctions
/**
* @covers ApiResult
*/
public function testDeprecatedFunctions()
{
// 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;
}
if (preg_match('/Use of ApiMain to ApiResult::__construct ' . 'was deprecated in MediaWiki \\d+.\\d+\\./', $errstr)) {
return true;
}
return false;
});
$reset = new ScopedCallback('restore_error_handler');
$context = new DerivativeContext(RequestContext::getMain());
$context->setConfig(new HashConfig(array('APIModules' => array(), 'APIFormatModules' => array(), 'APIMaxResultSize' => 42)));
$main = new ApiMain($context);
$result = TestingAccessWrapper::newFromObject(new ApiResult($main));
$this->assertSame(42, $result->maxSize);
$this->assertSame($main->getErrorFormatter(), $result->errorFormatter);
$this->assertSame($main, $result->mainForContinuation);
$result = new ApiResult(8388608);
$result->addContentValue(null, 'test', 'content');
$result->addContentValue(array('foo', 'bar'), 'test', 'content');
$result->addIndexedTagName(null, 'itn');
$result->addSubelementsList(null, array('sub'));
$this->assertSame(array('foo' => array('bar' => array('*' => 'content')), '*' => 'content'), $result->getData());
$result->setRawMode();
$this->assertSame(array('foo' => array('bar' => array('*' => 'content')), '*' => 'content', '_element' => 'itn', '_subelements' => array('sub')), $result->getData());
$arr = array();
ApiResult::setContent($arr, 'value');
ApiResult::setContent($arr, 'value2', 'foobar');
$this->assertSame(array(ApiResult::META_CONTENT => 'content', 'content' => 'value', 'foobar' => array(ApiResult::META_CONTENT => 'content', 'content' => 'value2')), $arr);
$result = new ApiResult(3);
$formatter = new ApiErrorFormatter_BackCompat($result);
$result->setErrorFormatter($formatter);
$result->disableSizeCheck();
$this->assertTrue($result->addValue(null, 'foo', '1234567890'));
$result->enableSizeCheck();
$this->assertSame(0, $result->getSize());
$this->assertFalse($result->addValue(null, 'foo', '1234567890'));
$arr = array('foo' => array('bar' => 1));
$result->setIndexedTagName_recursive($arr, 'itn');
$this->assertSame(array('foo' => array('bar' => 1, ApiResult::META_INDEXED_TAG_NAME => 'itn')), $arr);
$status = Status::newGood();
$status->fatal('parentheses', '1');
$status->fatal('parentheses', '2');
$status->warning('parentheses', '3');
$status->warning('parentheses', '4');
$this->assertSame(array(array('type' => 'error', 'message' => 'parentheses', 'params' => array(0 => '1', ApiResult::META_INDEXED_TAG_NAME => 'param')), array('type' => 'error', 'message' => 'parentheses', 'params' => array(0 => '2', ApiResult::META_INDEXED_TAG_NAME => 'param')), ApiResult::META_INDEXED_TAG_NAME => 'error'), $result->convertStatusToArray($status, 'error'));
$this->assertSame(array(array('type' => 'warning', 'message' => 'parentheses', 'params' => array(0 => '3', ApiResult::META_INDEXED_TAG_NAME => 'param')), array('type' => 'warning', 'message' => 'parentheses', 'params' => array(0 => '4', ApiResult::META_INDEXED_TAG_NAME => 'param')), ApiResult::META_INDEXED_TAG_NAME => 'warning'), $result->convertStatusToArray($status, 'warning'));
}