Skip to content

Commit

Permalink
feature #18036 [Serializer] XmlEncoder: Make load flags configurable …
Browse files Browse the repository at this point in the history
…(dunglas)

This PR was squashed before being merged into the 3.1-dev branch (closes #18036).

Discussion
----------

[Serializer] XmlEncoder: Make load flags configurable

| Q             | A
| ------------- | ---
| Branch        | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17987
| License       | MIT
| Doc PR        | todo

Commits
-------

0826068 [Serializer] XmlEncoder: Make load flags configurable
  • Loading branch information
fabpot committed Mar 31, 2016
2 parents 8acc601 + 0826068 commit b03d370
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Expand Up @@ -30,15 +30,18 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
private $format;
private $context;
private $rootNodeName = 'response';
private $loadOptions;

/**
* Construct new XmlEncoder and allow to change the root node element name.
*
* @param string $rootNodeName
* @param string $rootNodeName
* @param int|null $loadOptions A bit field of LIBXML_* constants
*/
public function __construct($rootNodeName = 'response')
public function __construct($rootNodeName = 'response', $loadOptions = null)
{
$this->rootNodeName = $rootNodeName;
$this->loadOptions = null !== $loadOptions ? $loadOptions : LIBXML_NONET | LIBXML_NOBLANKS;
}

/**
Expand Down Expand Up @@ -81,7 +84,7 @@ public function decode($data, $format, array $context = array())
libxml_clear_errors();

$dom = new \DOMDocument();
$dom->loadXML($data, LIBXML_NONET | LIBXML_NOBLANKS);
$dom->loadXML($data, $this->loadOptions);

libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
Expand Down

0 comments on commit b03d370

Please sign in to comment.