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

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Mar 6, 2016

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

{
$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.

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

@dunglas dunglas added the Ready label Mar 25, 2016
@dunglas
Copy link
Member Author

dunglas commented Mar 25, 2016

ping @symfony/deciders


/**
* 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").

@xabbuh
Copy link
Member

xabbuh commented Mar 26, 2016

👍 (apart from my last minor comment)

@dunglas
Copy link
Member Author

dunglas commented Mar 27, 2016

@xabbuh comment added

@fabpot
Copy link
Member

fabpot commented Mar 31, 2016

Thank you @dunglas.

@fabpot fabpot closed this Mar 31, 2016
fabpot added a commit that referenced this pull request Mar 31, 2016
…(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
@rvanlaak
Copy link
Contributor

Great 👍 Can someone point me in the direction how to override this settings for FOS\RestBundle\EventListener\BodyListener:114 as explained in #17987 (comment)?

@dunglas dunglas deleted the configurable_XmlEncoder branch March 31, 2016 10:48
@dunglas
Copy link
Member Author

dunglas commented Mar 31, 2016

Add this class with the new options as a new encoder: http://symfony.com/doc/current/cookbook/serializer.html#adding-normalizers-and-encoders

@fabpot fabpot mentioned this pull request May 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants