Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
83.33% |
5 / 6 |
CRAP | |
88.89% |
8 / 9 |
| XmlEncoder | |
0.00% |
0 / 1 |
|
83.33% |
5 / 6 |
7.07 | |
88.89% |
8 / 9 |
| getBaseEncoder | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
| setBaseEncoder | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| encode | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| supportsEncoding | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| decode | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| supportsDecoding | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\serialization\Encoder\XmlEncoder. | |
| */ | |
| namespace Drupal\serialization\Encoder; | |
| use Symfony\Component\Serializer\Encoder\EncoderInterface; | |
| use Symfony\Component\Serializer\Encoder\DecoderInterface; | |
| use Symfony\Component\Serializer\Encoder\XmlEncoder as BaseXmlEncoder; | |
| /** | |
| * 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. | |
| */ | |
| class XmlEncoder implements EncoderInterface, DecoderInterface { | |
| /** | |
| * The formats that this Encoder supports. | |
| * | |
| * @var array | |
| */ | |
| static protected $format = array('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(); | |
| } | |
| 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 = array()){ | |
| 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 = array()){ | |
| return $this->getBaseEncoder()->decode($data, $format, $context); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function supportsDecoding($format) { | |
| return in_array($format, static::$format); | |
| } | |
| } |