-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Allow to pass a single value for the groups opt #27503
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
Conversation
Huge 👍 because the previous |
Travis failure not related. |
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.
Can you add a note in the changelog file?
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.
Nice job !
if (isset($context[static::GROUPS]) && \is_array($context[static::GROUPS])) { | ||
$groups = $context[static::GROUPS]; | ||
if (isset($context[static::GROUPS])) { | ||
$groups = (array) $context[static::GROUPS]; |
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.
shouldn't this check is_scalar||is_array instead of casting objects?
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.
done
b7e8a89
to
5b39203
Compare
Thank you @dunglas. |
…ps opt (dunglas) This PR was merged into the 4.2-dev branch. Discussion ---------- [Serializer] Allow to pass a single value for the groups opt | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | n/a | License | MIT | Doc PR | todo Shortcut syntax similar to #20509 but for the context: allows to pass a string instead of an array of string in the serialization context when only one group if used. Before: ```php $serializer->serialize($foo, 'json', ['groups' => ['myGroup']]; /** @ApiResource(normalizationContext={"groups"={"myGroup"}}) */ ``` After: ```php $serializer->serialize($foo, 'json', ['groups' => 'myGroup']; /** @ApiResource(normalizationContext={"groups"="myGroup") */ ``` Commits ------- 5b39203 [Serializer] Allow to pass a single value for the groups opt
… opt (dunglas, javiereguiluz) This PR was merged into the master branch. Discussion ---------- [Serializer] Allow to pass a single value for the groups opt symfony/symfony#27503 Commits ------- ae558f4 Added the missing versionadded directive e4eae25 Replaced a "note" by a "tip" 5e0a91e [Serializer] Allow to pass a single value for the groups opt
Shortcut syntax similar to #20509 but for the context: allows to pass a string instead of an array of string in the serialization context when only one group if used.
Before:
After: