8000 [Serializer] XmlEncoder: Make load flags configurable by dunglas · Pull Request #18036 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] XmlEncoder: Make load flags configurable #18036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Serializer] XmlEncoder: Make load flags configurable
  • Loading branch information
dunglas committed Mar 6, 2016
commit 7295402fa6e261436f0fb2f65e25ab118f55a7af
11 changes: 8 additions & 3 deletions src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a short explanation what $loadOptions means (something like "a bit field of LIBXML_ constants").

*/
public function __construct($rootNodeName = 'response')
public function __construct($rootNodeName = 'response', $loadOptions = null)
{
$this->rootNodeName = $rootNodeName;
$this->loadOptions = $loadOptions ?: LIBXML_NONET | LIBXML_NOBLANKS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->loadOptions = null !== $loadOptions ?: LIBXML_NONET | LIBXML_NOBLANKS;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait, the suggestion was bad, it must now be $this->loadOptions = null !== $loadOptions ? $loadOptions : LIBXML_NONET | LIBXML_NOBLANKS;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy/pasted without care, sorry. It's fixed now.

}

/**
Expand Down Expand Up @@ -80,8 +83,10 @@ public function decode($data, $format, array $context = array())
$disableEntities = libxml_disable_entity_loader(true);
libxml_clear_errors();

$loadOptions = isset($context['xml_load_options']) ? $context['xml_load_options'] : $this->loadOptions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really a good idea to make this overridable through the context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, I'll update the PR.


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

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