Skip to content

Commit 302248f

Browse files
Rely on iconv and symfony/polyfill-*
1 parent d00162f commit 302248f

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed

Encoder/JsonDecode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function decode($data, $format, array $context = array())
108108
}
109109

110110
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
111-
throw new UnexpectedValueException(JsonEncoder::getLastErrorMessage());
111+
throw new UnexpectedValueException(json_last_error_message());
112112
}
113113

114114
return $decodedData;

Encoder/JsonEncode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function encode($data, $format, array $context = array())
5656
$encodedJson = json_encode($data, $context['json_encode_options']);
5757

5858
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
59-
throw new UnexpectedValueException(JsonEncoder::getLastErrorMessage());
59+
throw new UnexpectedValueException(json_last_error_message());
6060
}
6161

6262
return $encodedJson;

Encoder/JsonEncoder.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,13 @@ public function supportsDecoding($format)
100100
* Resolves json_last_error message.
101101
*
102102
* @return string
103+
*
104+
* @deprecated since 2.8, to be removed in 3.0. Use json_last_error_msg() instead.
103105
*/
104106
public static function getLastErrorMessage()
105107
{
106-
if (function_exists('json_last_error_msg')) {
107-
return json_last_error_msg();
108-
}
109-
110-
switch (json_last_error()) {
111-
case JSON_ERROR_DEPTH:
112-
return 'Maximum stack depth exceeded';
113-
case JSON_ERROR_STATE_MISMATCH:
114-
return 'Underflow or the modes mismatch';
115-
case JSON_ERROR_CTRL_CHAR:
116-
return 'Unexpected control character found';
117-
case JSON_ERROR_SYNTAX:
118-
return 'Syntax error, malformed JSON';
119-
case JSON_ERROR_UTF8:
120-
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
121-
default:
122-
return 'Unknown error';
123-
}
108+
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use json_last_error_msg() instead.', E_USER_DEPRECATED);
109+
110+
return json_last_error_msg();
124111
}
125112
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=5.3.9"
19+
"php": ">=5.3.9",
20+
"symfony/polyfill-php54": "~1.0"
2021
},
2122
"require-dev": {
2223
"symfony/yaml": "~2.0,>=2.0.5|~3.0.0",

0 commit comments

Comments
 (0)