-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Added support for using the keys of an array as XML tag. #129
Conversation
What does the Symfony Serializer do here? Can we mirror its behavior for this case? // cc @Seldaek |
The symfony seralizer basically uses PCRE to check if an element name is valid -> https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php#L196 |
Great stuff, thanks |
@schmittjoh I guess this is a yes from @Seldaek ;) Will adjust it sometime today. |
Updated |
* | ||
* @return Boolean | ||
*/ | ||
final protected function isElementNameValid($name) |
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.
I think we can use private
here as the class is not designed for extending.
How about renaming |
Yeah sure, |
Before I forget it. Right now the tag name |
Wouldn't an exception be more appropriate as this seems like something that a developer would want to fix, no? |
I'm not sure about this, an Exception seems a little bit too "hard" for me, but on the other hand the developer could also be confused when he used an invalid tag name and he can't find it in the generated output. |
I don't think an exception is appropriate at all. As I said on #59 (comment) - if it is user data that you can't control, it just might break everything in production, which is much worse than just "losing" one key IMO. |
Good point, I will keep it as it is right now. |
Refactored annotation name and slightly updated doc. |
~~~~~~~ | ||
This allows you to use the keys of an array as xml tags. | ||
**Note:** When a key is an invalid xml tag name (e.g. 1_foo) the tag name *entry* will be used instead of the key. |
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.
This should be
.. note ::
When a key ...
to be formatted correctly on the website.
Fixed. Do you want me to squash the commits? |
~~~~~~~~~~~~~~~~~ | ||
This allows you to use the keys of an array as xml tags. | ||
.. note :: |
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.
There must be a blank line before and after the .. note ::
line.
Yeah, please squash them. |
Squashed and fixed. |
Thanks, merged! |
btw, can you add support for this to the XML and YAML metadata drivers as well? |
Sure, will add them tomorrow. |
This PR is merged, but using Am I doing something wrong? My array is also dinamically generated from user data, and I cannot use objects. |
+1 Idem to naroga, in xml I have always ... instead of the array keys. |
As discussed in #59 this PR adds the possibility to use the keys of an array as XML tags.
Example:
Currently I only check for numeric keys to avoid problems with naming convention. But when a key looks like "1_foo" an exception is thrown. Possible solutions could be:
What do you think?