Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / serialization / src / Encoder / XmlEncoder.php
1 <?php
2
3 namespace Drupal\serialization\Encoder;
4
5 use Symfony\Component\Serializer\Encoder\EncoderInterface;
6 use Symfony\Component\Serializer\Encoder\DecoderInterface;
7 use Symfony\Component\Serializer\Encoder\XmlEncoder as BaseXmlEncoder;
8 use Symfony\Component\Serializer\SerializerAwareInterface;
9 use Symfony\Component\Serializer\SerializerAwareTrait;
10
11 /**
12  * Adds XML support for serializer.
13  *
14  * This acts as a wrapper class for Symfony's XmlEncoder so that it is not
15  * implementing NormalizationAwareInterface, and can be normalized externally.
16  *
17  * @internal
18  *   This encoder should not be used directly. Rather, use the `serializer`
19  *   service.
20  */
21 class XmlEncoder implements SerializerAwareInterface, EncoderInterface, DecoderInterface {
22
23   use SerializerAwareTrait;
24
25   /**
26    * The formats that this Encoder supports.
27    *
28    * @var array
29    */
30   static protected $format = ['xml'];
31
32   /**
33    * An instance of the Symfony XmlEncoder to perform the actual encoding.
34    *
35    * @var \Symfony\Component\Serializer\Encoder\XmlEncoder
36    */
37   protected $baseEncoder;
38
39   /**
40    * Gets the base encoder instance.
41    *
42    * @return \Symfony\Component\Serializer\Encoder\XmlEncoder
43    *   The base encoder.
44    */
45   public function getBaseEncoder() {
46     if (!isset($this->baseEncoder)) {
47       $this->baseEncoder = new BaseXmlEncoder();
48       $this->baseEncoder->setSerializer($this->serializer);
49     }
50
51     return $this->baseEncoder;
52   }
53
54   /**
55    * Sets the base encoder instance.
56    *
57    * @param \Symfony\Component\Serializer\Encoder\XmlEncoder $encoder
58    */
59   public function setBaseEncoder($encoder) {
60     $this->baseEncoder = $encoder;
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function encode($data, $format, array $context = []) {
67     return $this->getBaseEncoder()->encode($data, $format, $context);
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function supportsEncoding($format) {
74     return in_array($format, static::$format);
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function decode($data, $format, array $context = []) {
81     return $this->getBaseEncoder()->decode($data, $format, $context);
82   }
83
84   /**
85    * {@inheritdoc}
86    */
87   public function supportsDecoding($format) {
88     return in_array($format, static::$format);
89   }
90
91 }