| @@ 74-97 (lines=24) @@ | ||
| 71 | * @return mixed | |
| 72 | * @throws ConversionException | |
| 73 | */ | |
| 74 | private function decodeJson($value) | |
| 75 |     { | |
| 76 | $decoded = json_decode($value, true); | |
| 77 | ||
| 78 |         switch (json_last_error()) { | |
| 79 | case JSON_ERROR_NONE: | |
| 80 |                 if (!is_array($decoded)) { | |
| 81 | throw ConversionException::conversionFailed($value, 'Json was not an array'); | |
| 82 | } | |
| 83 | return $decoded; | |
| 84 | case JSON_ERROR_DEPTH: | |
| 85 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, maximum stack depth exceeded.'); | |
| 86 | case JSON_ERROR_STATE_MISMATCH: | |
| 87 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, underflow or the nodes mismatch.'); | |
| 88 | case JSON_ERROR_CTRL_CHAR: | |
| 89 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, unexpected control character found.'); | |
| 90 | case JSON_ERROR_SYNTAX: | |
| 91 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, syntax error - malformed JSON.'); | |
| 92 | case JSON_ERROR_UTF8: | |
| 93 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, malformed UTF-8 characters (incorrectly encoded?)'); | |
| 94 | default: | |
| 95 | throw ConversionException::conversionFailed($value, 'Could not decode Json'); | |
| 96 | } | |
| 97 | } | |
| 98 | } | |
| 99 | ||
| @@ 90-113 (lines=24) @@ | ||
| 87 | * @return mixed | |
| 88 | * @throws ConversionException | |
| 89 | */ | |
| 90 | private function decodeJson($value) | |
| 91 |     { | |
| 92 | $decoded = json_decode($value, true); | |
| 93 | ||
| 94 |         switch (json_last_error()) { | |
| 95 | case JSON_ERROR_NONE: | |
| 96 |                 if (!is_array($decoded)) { | |
| 97 | throw ConversionException::conversionFailed($value, 'Json was not an array'); | |
| 98 | } | |
| 99 | return $decoded; | |
| 100 | case JSON_ERROR_DEPTH: | |
| 101 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, maximum stack depth exceeded.'); | |
| 102 | case JSON_ERROR_STATE_MISMATCH: | |
| 103 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, underflow or the nodes mismatch.'); | |
| 104 | case JSON_ERROR_CTRL_CHAR: | |
| 105 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, unexpected control character found.'); | |
| 106 | case JSON_ERROR_SYNTAX: | |
| 107 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, syntax error - malformed JSON.'); | |
| 108 | case JSON_ERROR_UTF8: | |
| 109 | throw ConversionException::conversionFailed($value, 'Could not decode JSON, malformed UTF-8 characters (incorrectly encoded?)'); | |
| 110 | default: | |
| 111 | throw ConversionException::conversionFailed($value, 'Could not decode Json'); | |
| 112 | } | |
| 113 | } | |
| 114 | } | |
| 115 | ||