You are here

private function JsonEncoder::getJsonEncode in Drupal 8

Instantiates a JsonEncode instance.

@internal this exists to bridge Symfony 3 to Symfony 4, and can be removed once Drupal requires Symfony 4.2 or higher.

1 call to JsonEncoder::getJsonEncode()
JsonEncoder::__construct in core/modules/serialization/src/Encoder/JsonEncoder.php

File

core/modules/serialization/src/Encoder/JsonEncoder.php, line 41

Class

JsonEncoder
Adds 'ajax to the supported content types of the JSON encoder'

Namespace

Drupal\serialization\Encoder

Code

private function getJsonEncode() {

  // 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;
  $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);
}