-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Changes from 1 commit
7295402
cfcd2b7
fc38acb
8fe793b
a9c3e16
76946e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
public function __construct($rootNodeName = 'response') | ||
public function __construct($rootNodeName = 'response', $loadOptions = null) | ||
{ | ||
$this->rootNodeName = $rootNodeName; | ||
$this->loadOptions = $loadOptions ?: LIBXML_NONET | LIBXML_NOBLANKS; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh wait, the suggestion was bad, it must now be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copy/pasted without care, sorry. It's fixed now. |
||
} | ||
|
||
/** | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment.
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").