You are here

public static function FeedsExJsonUtility::translateError in Feeds extensible parsers 7

Same name and namespace in other branches
  1. 7.2 src/Json/Utility.php \FeedsExJsonUtility::translateError()

Translates an error message.

Parameters

int $error: The JSON error.

Return value

string The JSON parsing error message.

2 calls to FeedsExJsonUtility::translateError()
FeedsExJmesPath::getErrors in src/FeedsExJmesPath.inc
Returns the errors after parsing.
FeedsExJsonPath::getErrors in src/FeedsExJsonPath.inc
Returns the errors after parsing.

File

src/Json/Utility.php, line 22
Contains FeedsExJsonUtility.

Class

FeedsExJsonUtility
Various helpers for handling JSON.

Code

public static function translateError($error) {

  // This shouldn't get called for PHP < 5.3.0.
  if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    return 'Unknown error';
  }
  if (version_compare(PHP_VERSION, '5.3.3', '>=')) {
    switch ($error) {
      case JSON_ERROR_UTF8:
        return 'Malformed UTF-8 characters, possibly incorrectly encoded';
    }
  }
  if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
    switch ($error) {
      case JSON_ERROR_RECURSION:
        return 'One or more recursive references in the value to be encoded';
      case JSON_ERROR_INF_OR_NAN:
        return 'One or more NAN or INF values in the value to be encoded';
      case JSON_ERROR_UNSUPPORTED_TYPE:
        return 'A value of a type that cannot be encoded was given';
    }
  }
  switch ($error) {
    case JSON_ERROR_NONE:
      return 'No error has occurred';
    case JSON_ERROR_DEPTH:
      return 'The maximum stack depth has been exceeded';
    case JSON_ERROR_STATE_MISMATCH:
      return 'Invalid or malformed JSON';
    case JSON_ERROR_CTRL_CHAR:
      return 'Control character error, possibly incorrectly encoded';
    case JSON_ERROR_SYNTAX:
      return 'Syntax error';
    default:
      return 'Unknown error';
  }
}