Chris@0: encodingImpl = $encodingImpl ?: $this->getJsonEncode(); Chris@18: $this->decodingImpl = $decodingImpl ?: $this->getJsonDecode(); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Instantiates a JsonEncode instance. Chris@18: * Chris@18: * @internal this exists to bridge Symfony 3 to Symfony 4, and can be removed Chris@18: * once Drupal requires Symfony 4.2 or higher. Chris@18: */ Chris@18: private function getJsonEncode() { Chris@0: // Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be Chris@0: // embedded into HTML. Chris@0: // @see \Symfony\Component\HttpFoundation\JsonResponse Chris@0: $json_encoding_options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT; Chris@18: $reflection = new \ReflectionClass(JsonEncode::class); Chris@18: if (array_key_exists('OPTIONS', $reflection->getConstants())) { Chris@18: return new JsonEncode([JsonEncode::OPTIONS => $json_encoding_options]); Chris@18: } Chris@18: return new JsonEncode($json_encoding_options); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Instantiates a JsonDecode instance. Chris@18: * Chris@18: * @internal this exists to bridge Symfony 3 to Symfony 4, and can be removed Chris@18: * once Drupal requires Symfony 4.2 or higher. Chris@18: */ Chris@18: private function getJsonDecode() { Chris@18: $reflection = new \ReflectionClass(JsonDecode::class); Chris@18: if (array_key_exists('ASSOCIATIVE', $reflection->getConstants())) { Chris@18: return new JsonDecode([JsonDecode::ASSOCIATIVE => TRUE]); Chris@18: } Chris@18: return new JsonDecode(TRUE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function supportsEncoding($format) { Chris@0: return in_array($format, static::$format); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function supportsDecoding($format) { Chris@0: return in_array($format, static::$format); Chris@0: } Chris@0: Chris@0: }