class 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.

Hierarchy

Expanded class hierarchy of XmlEncoder

1 string reference to 'XmlEncoder'
serialization.services.yml in drupal/core/modules/serialization/serialization.services.yml
drupal/core/modules/serialization/serialization.services.yml
1 service uses XmlEncoder

File

drupal/core/modules/serialization/lib/Drupal/serialization/Encoder/XmlEncoder.php, line 21
Contains \Drupal\serialization\Encoder\XmlEncoder.

Namespace

Drupal\serialization\Encoder
View source
class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, DecoderInterface {

  /**
   * The formats that this Encoder supports.
   *
   * @var array
   */
  protected static $format = array(
    'xml',
  );

  /**
   * An instance of the Symfony XmlEncoder to perform the actual encoding.
   *
   * @var \Symfony\Component\Serializer\Encoder\XmlEncoder
   */
  protected $baseEncoder;

  /**
   * Constucts the XmlEncoder object, creating a BaseXmlEncoder class also.
   */
  public function __construct() {
    $this->baseEncoder = new BaseXmlEncoder();
  }

  /**
   * Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::encode().
   */
  public function encode($data, $format, array $context = array()) {
    $normalized = $this->serializer
      ->normalize($data, $format, $context);
    return $this->baseEncoder
      ->encode($normalized, $format, $context);
  }

  /**
   * Implements \Symfony\Component\Serializer\Encoder\JsonEncoder::supportsEncoding().
   */
  public function supportsEncoding($format) {
    return in_array($format, static::$format);
  }

  /**
   * Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::decode().
   */
  public function decode($data, $format, array $context = array()) {
    return $this->baseEncoder
      ->decode($data, $format, $context);
  }

  /**
   * Implements \Symfony\Component\Serializer\Encoder\JsonEncoder::supportsDecoding().
   */
  public function supportsDecoding($format) {
    return in_array($format, static::$format);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SerializerAwareEncoder::$serializer protected property
SerializerAwareEncoder::setSerializer public function Sets the owning Serializer object Overrides SerializerAwareInterface::setSerializer
XmlEncoder::$baseEncoder protected property An instance of the Symfony XmlEncoder to perform the actual encoding.
XmlEncoder::$format protected static property The formats that this Encoder supports.
XmlEncoder::decode public function Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::decode(). Overrides DecoderInterface::decode
XmlEncoder::encode public function Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::encode(). Overrides EncoderInterface::encode
XmlEncoder::supportsDecoding public function Implements \Symfony\Component\Serializer\Encoder\JsonEncoder::supportsDecoding(). Overrides DecoderInterface::supportsDecoding
XmlEncoder::supportsEncoding public function Implements \Symfony\Component\Serializer\Encoder\JsonEncoder::supportsEncoding(). Overrides EncoderInterface::supportsEncoding
XmlEncoder::__construct public function Constucts the XmlEncoder object, creating a BaseXmlEncoder class also.