Unverified Commit 67ed5a5a authored by larowlan's avatar larowlan
Browse files

Issue #3020385 by catch, vacho, alexpott, larowlan, borisson_, sjerdo: Symfony...

Issue #3020385 by catch, vacho, alexpott, larowlan, borisson_, sjerdo: Symfony 3 and Symfony ^4.2 JsonEncode constructors are incompatible
parent 6077050e
......@@ -39,13 +39,12 @@ public function __construct(JsonEncode $encodingImpl = NULL, JsonDecode $decodin
* once Drupal requires Symfony 4.2 or higher.
*/
private function getJsonEncode() {
// defined() does not trigger the autoloader, so do that first.
class_exists('JsonEncode');
// Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be
// embedded into HTML.
// @see \Symfony\Component\HttpFoundation\JsonResponse
$json_encoding_options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
if (defined('JsonEncode::OPTIONS')) {
$reflection = new \ReflectionClass(JsonEncode::class);
if (array_key_exists('OPTIONS', $reflection->getConstants())) {
return new JsonEncode([JsonEncode::OPTIONS => $json_encoding_options]);
}
return new JsonEncode($json_encoding_options);
......@@ -58,10 +57,9 @@ class_exists('JsonEncode');
* once Drupal requires Symfony 4.2 or higher.
*/
private function getJsonDecode() {
// defined() does not trigger the autoloader, so do that first.
class_exists('JsonDecode');
if (defined('JsonDecode::OPTIONS')) {
return new JsonDecode([JsonDecode::OPTIONS => [JsonDecode::ASSOCIATIVE => TRUE]]);
$reflection = new \ReflectionClass(JsonDecode::class);
if (array_key_exists('ASSOCIATIVE', $reflection->getConstants())) {
return new JsonDecode([JsonDecode::ASSOCIATIVE => TRUE]);
}
return new JsonDecode(TRUE);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment