Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / serialization / src / Encoder / JsonEncoder.php
1 <?php
2
3 namespace Drupal\serialization\Encoder;
4
5 use Symfony\Component\Serializer\Encoder\DecoderInterface;
6 use Symfony\Component\Serializer\Encoder\EncoderInterface;
7 use Symfony\Component\Serializer\Encoder\JsonDecode;
8 use Symfony\Component\Serializer\Encoder\JsonEncode;
9 use Symfony\Component\Serializer\Encoder\JsonEncoder as BaseJsonEncoder;
10
11 /**
12  * Adds 'ajax to the supported content types of the JSON encoder'
13  *
14  * @internal
15  *   This encoder should not be used directly. Rather, use the `serializer`
16  *   service.
17  */
18 class JsonEncoder extends BaseJsonEncoder implements EncoderInterface, DecoderInterface {
19
20   /**
21    * The formats that this Encoder supports.
22    *
23    * @var array
24    */
25   protected static $format = ['json', 'ajax'];
26
27   /**
28    * {@inheritdoc}
29    */
30   public function __construct(JsonEncode $encodingImpl = NULL, JsonDecode $decodingImpl = NULL) {
31     // Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be
32     // embedded into HTML.
33     // @see \Symfony\Component\HttpFoundation\JsonResponse
34     $json_encoding_options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
35     $this->encodingImpl = $encodingImpl ?: new JsonEncode($json_encoding_options);
36     $this->decodingImpl = $decodingImpl ?: new JsonDecode(TRUE);
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function supportsEncoding($format) {
43     return in_array($format, static::$format);
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function supportsDecoding($format) {
50     return in_array($format, static::$format);
51   }
52
53 }