XmlEncoder.php in Drupal 10
File
core/modules/serialization/src/Encoder/XmlEncoder.php
View source
<?php
namespace Drupal\serialization\Encoder;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\XmlEncoder as BaseXmlEncoder;
use Symfony\Component\Serializer\SerializerAwareInterface;
use Symfony\Component\Serializer\SerializerAwareTrait;
class XmlEncoder implements SerializerAwareInterface, EncoderInterface, DecoderInterface {
use SerializerAwareTrait;
protected static $format = [
'xml',
];
protected $baseEncoder;
public function getBaseEncoder() {
if (!isset($this->baseEncoder)) {
$this->baseEncoder = new BaseXmlEncoder();
$this->baseEncoder
->setSerializer($this->serializer);
}
return $this->baseEncoder;
}
public function setBaseEncoder($encoder) {
$this->baseEncoder = $encoder;
}
public function encode($data, $format, array $context = []) : string {
return $this
->getBaseEncoder()
->encode($data, $format, $context);
}
public function supportsEncoding(string $format, array $context = []) : bool {
return in_array($format, static::$format);
}
public function decode($data, $format, array $context = []) : mixed {
return $this
->getBaseEncoder()
->decode($data, $format, $context);
}
public function supportsDecoding(string $format, array $context = []) : bool {
return in_array($format, static::$format);
}
}