JsonEncoder.php in Drupal 9
File
core/modules/serialization/src/Encoder/JsonEncoder.php
View source
<?php
namespace Drupal\serialization\Encoder;
use Symfony\Component\Serializer\Encoder\JsonDecode;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\Encoder\JsonEncoder as BaseJsonEncoder;
class JsonEncoder extends BaseJsonEncoder {
protected static $format = [
'json',
'ajax',
];
public function __construct(JsonEncode $encodingImpl = NULL, JsonDecode $decodingImpl = NULL) {
$json_encoding_options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
$this->encodingImpl = $encodingImpl ?: new JsonEncode([
JsonEncode::OPTIONS => $json_encoding_options,
]);
$this->decodingImpl = $decodingImpl ?: new JsonDecode([
JsonDecode::ASSOCIATIVE => TRUE,
]);
}
public function supportsEncoding($format) {
return in_array($format, static::$format);
}
public function supportsDecoding($format) {
return in_array($format, static::$format);
}
}
Classes
Name |
Description |
JsonEncoder |
Adds 'ajax' to the supported content types of the JSON encoder. |