class XmlEncoder in Drupal 9
Same name and namespace in other branches
- 8 core/modules/serialization/src/Encoder/XmlEncoder.php \Drupal\serialization\Encoder\XmlEncoder
Adds XML support for serializer.
This acts as a wrapper class for Symfony's XmlEncoder so that it is not implementing NormalizationAwareInterface, and can be normalized externally.
@internal This encoder should not be used directly. Rather, use the `serializer` service.
Hierarchy
- class \Drupal\serialization\Encoder\XmlEncoder implements \Symfony\Component\Serializer\SerializerAwareInterface, \Symfony\Component\Serializer\Encoder\EncoderInterface, \Symfony\Component\Serializer\Encoder\DecoderInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
Expanded class hierarchy of XmlEncoder
2 files declare their use of XmlEncoder
- ResourceResponseSubscriberTest.php in core/
modules/ rest/ tests/ src/ Unit/ EventSubscriber/ ResourceResponseSubscriberTest.php - XmlEncoderTest.php in core/
modules/ serialization/ tests/ src/ Unit/ Encoder/ XmlEncoderTest.php
1 string reference to 'XmlEncoder'
- serialization.services.yml in core/
modules/ serialization/ serialization.services.yml - core/modules/serialization/serialization.services.yml
1 service uses XmlEncoder
- serializer.encoder.xml in core/
modules/ serialization/ serialization.services.yml - Drupal\serialization\Encoder\XmlEncoder
File
- core/
modules/ serialization/ src/ Encoder/ XmlEncoder.php, line 21
Namespace
Drupal\serialization\EncoderView source
class XmlEncoder implements SerializerAwareInterface, EncoderInterface, DecoderInterface {
use SerializerAwareTrait;
/**
* The formats that this Encoder supports.
*
* @var array
*/
protected static $format = [
'xml',
];
/**
* An instance of the Symfony XmlEncoder to perform the actual encoding.
*
* @var \Symfony\Component\Serializer\Encoder\XmlEncoder
*/
protected $baseEncoder;
/**
* Gets the base encoder instance.
*
* @return \Symfony\Component\Serializer\Encoder\XmlEncoder
* The base encoder.
*/
public function getBaseEncoder() {
if (!isset($this->baseEncoder)) {
$this->baseEncoder = new BaseXmlEncoder();
$this->baseEncoder
->setSerializer($this->serializer);
}
return $this->baseEncoder;
}
/**
* Sets the base encoder instance.
*
* @param \Symfony\Component\Serializer\Encoder\XmlEncoder $encoder
*/
public function setBaseEncoder($encoder) {
$this->baseEncoder = $encoder;
}
/**
* {@inheritdoc}
*/
public function encode($data, $format, array $context = []) {
return $this
->getBaseEncoder()
->encode($data, $format, $context);
}
/**
* {@inheritdoc}
*/
public function supportsEncoding($format) {
return in_array($format, static::$format);
}
/**
* {@inheritdoc}
*/
public function decode($data, $format, array $context = []) {
return $this
->getBaseEncoder()
->decode($data, $format, $context);
}
/**
* {@inheritdoc}
*/
public function supportsDecoding($format) {
return in_array($format, static::$format);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
XmlEncoder:: |
protected | property | An instance of the Symfony XmlEncoder to perform the actual encoding. | |
XmlEncoder:: |
protected static | property | The formats that this Encoder supports. | |
XmlEncoder:: |
public | function | ||
XmlEncoder:: |
public | function | ||
XmlEncoder:: |
public | function | Gets the base encoder instance. | |
XmlEncoder:: |
public | function | Sets the base encoder instance. | |
XmlEncoder:: |
public | function | ||
XmlEncoder:: |
public | function |