本文整理汇总了PHP中Status::getErrorsByType方法的典型用法代码示例。如果您正苦于以下问题:PHP Status::getErrorsByType方法的具体用法?PHP Status::getErrorsByType怎么用?PHP Status::getErrorsByType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Status
的用法示例。
在下文中一共展示了Status::getErrorsByType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStatusError
/**
* Get error message key and parameters from status
*
* @param \Status $status
* @return array of error message key, and message parameters as an array
* @throws Exception if called on an "OK" Status
*/
public function getStatusError(\Status $status)
{
if ($status->isOK()) {
throw new \Exception('Status contains no errors');
}
$errors = $status->getErrorsByType('error');
if (!empty($errors[0]['message'])) {
$message = $errors[0]['message'];
$params = $errors[0]['params'];
} else {
$message = 'fbconnect-error';
$params = [];
}
return [$message, $params];
}
示例2: testGetErrorsByType
/**
* @covers Status::getErrorsByType
*/
public function testGetErrorsByType()
{
$status = new Status();
$warning = new Message('warning111');
$error = new Message('error111');
$status->warning($warning);
$status->error($error);
$warnings = $status->getErrorsByType('warning');
$errors = $status->getErrorsByType('error');
$this->assertCount(1, $warnings);
$this->assertCount(1, $errors);
$this->assertEquals($warning, $warnings[0]['message']);
$this->assertEquals($error, $errors[0]['message']);
}
示例3: convertStatusToArray
/**
* Converts a Status object to an array suitable for addValue
* @param Status $status
* @param string $errorType
* @return array
*/
public function convertStatusToArray($status, $errorType = 'error')
{
if ($status->isGood()) {
return array();
}
$result = array();
foreach ($status->getErrorsByType($errorType) as $error) {
$this->setIndexedTagName($error['params'], 'param');
$result[] = $error;
}
$this->setIndexedTagName($result, $errorType);
return $result;
}
示例4: arrayFromStatus
public function arrayFromStatus(Status $status, $type = 'error', $format = null)
{
if ($status->isGood() || !$status->errors) {
return [];
}
$result = [];
foreach ($status->getErrorsByType($type) as $error) {
if ($error['message'] instanceof Message) {
$error = ['message' => $error['message']->getKey(), 'params' => $error['message']->getParams()] + $error;
}
ApiResult::setIndexedTagName($error['params'], 'param');
$result[] = $error;
}
ApiResult::setIndexedTagName($result, $type);
return $result;
}
示例5: getErrors
/**
* @param string|array|Status $err
* @return string
*/
function getErrors($err)
{
if (!$err) {
$errors = array();
} elseif ($err instanceof Status) {
if ($err->isOK()) {
$errors = array();
} else {
$errors = $err->getErrorsByType('error');
foreach ($errors as &$error) {
// Input: array( 'message' => 'foo', 'errors' => array( 'a', 'b', 'c' ) )
// Output: array( 'foo', 'a', 'b', 'c' )
$error = array_merge(array($error['message']), $error['params']);
}
}
} else {
$errors = $err;
if (!is_array($errors)) {
$errors = array($errors);
}
}
foreach ($errors as &$error) {
if (is_array($error)) {
$msg = array_shift($error);
} else {
$msg = $error;
$error = array();
}
// if the error is already a message object, don't use it as a message key
if (!$msg instanceof Message) {
$error = $this->msg($msg, $error)->parse();
} else {
$error = $msg->parse();
}
$error = new OOUI\HtmlSnippet($error);
}
// Used in getBody()
$this->oouiErrors = $errors;
return '';
}
示例6: getErrorFromStatus
/**
* Get error (as code, string) from a Status object.
*
* @since 1.23
* @param Status $status
* @param array|null &$extraData Set if extra data from IApiMessage is available (since 1.27)
* @return array Array of code and error string
* @throws MWException
*/
public function getErrorFromStatus($status, &$extraData = null)
{
if ($status->isGood()) {
throw new MWException('Successful status passed to ApiBase::dieStatus');
}
$errors = $status->getErrorsByType('error');
if (!$errors) {
// No errors? Assume the warnings should be treated as errors
$errors = $status->getErrorsByType('warning');
}
if (!$errors) {
// Still no errors? Punt
$errors = [['message' => 'unknownerror-nocode', 'params' => []]];
}
// Cannot use dieUsageMsg() because extensions might return custom
// error messages.
if ($errors[0]['message'] instanceof Message) {
$msg = $errors[0]['message'];
if ($msg instanceof IApiMessage) {
$extraData = $msg->getApiData();
$code = $msg->getApiCode();
} else {
$code = $msg->getKey();
}
} else {
$code = $errors[0]['message'];
$msg = wfMessage($code, $errors[0]['params']);
}
if (isset(ApiBase::$messageMap[$code])) {
// Translate message to code, for backwards compatibility
$code = ApiBase::$messageMap[$code]['code'];
}
return [$code, $msg->inLanguage('en')->useDatabase(false)->plain()];
}
示例7: getErrorsOrWarnings
/**
* @param string|array|Status $elements
* @param string $elementsType
* @return string
*/
function getErrorsOrWarnings($elements, $elementsType)
{
if (!in_array($elementsType, ['error', 'warning'])) {
throw new DomainException($elementsType . ' is not a valid type.');
}
if (!$elements) {
$errors = [];
} elseif ($elements instanceof Status) {
if ($elements->isGood()) {
$errors = [];
} else {
$errors = $elements->getErrorsByType($elementsType);
foreach ($errors as &$error) {
// Input: [ 'message' => 'foo', 'errors' => [ 'a', 'b', 'c' ] ]
// Output: [ 'foo', 'a', 'b', 'c' ]
$error = array_merge([$error['message']], $error['params']);
}
}
} elseif ($elementsType === 'errors') {
$errors = $elements;
if (!is_array($errors)) {
$errors = [$errors];
}
} else {
$errors = [];
}
foreach ($errors as &$error) {
$error = $this->getMessage($error)->parse();
$error = new OOUI\HtmlSnippet($error);
}
// Used in getBody()
if ($elementsType === 'error') {
$this->oouiErrors = $errors;
} else {
$this->oouiWarnings = $errors;
}
return '';
}
示例8: getErrors
/**
* @param string|array|Status $err
* @return string
*/
function getErrors($err)
{
if (!$err) {
$errors = [];
} elseif ($err instanceof Status) {
if ($err->isOK()) {
$errors = [];
} else {
$errors = $err->getErrorsByType('error');
foreach ($errors as &$error) {
// Input: array( 'message' => 'foo', 'errors' => array( 'a', 'b', 'c' ) )
// Output: array( 'foo', 'a', 'b', 'c' )
$error = array_merge([$error['message']], $error['params']);
}
}
} else {
$errors = $err;
if (!is_array($errors)) {
$errors = [$errors];
}
}
foreach ($errors as &$error) {
$error = $this->getMessage($error)->parse();
$error = new OOUI\HtmlSnippet($error);
}
// Used in getBody()
$this->oouiErrors = $errors;
return '';
}