-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add a MaxDepth option #17113
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
* | ||
* @param int|null $maxDepth | ||
*/ | ||
public function setMaxDepth($maxDepth); |
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.
Isn't that a BC break?
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.
Good catch, needs a new interface...
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.
By the way, I think than introducing such interfaces was a (my) mistake. Serializer Metadata are value objects. Nobody will (nor should) implement these interfaces. Composition is better for "extending" metadata.
What do you think about marking them as @internal
(and even deprecated) @symfony/deciders?
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 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.
#17114 merged
* | ||
* @return array | ||
*/ | ||
protected function setAttribute($data, $attribute, $attributeValue) |
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.
What do you think about using the reference operator &$data
to avoid useless copy of the array?
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.
You can also add an array
type hint.
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 prefer to avoid references when possible (http://schlueters.de/blog/archives/125-do-not-use-php-references.html).
Typehint added.
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.
Ok makes sense.
👍 to merge this. |
Sounds good to me |
This PR was merged into the 2.7 branch. Discussion ---------- [Serializer] Make metadata interfaces internal | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17113 (comment) | License | MIT | Doc PR | n/a Introducing such interfaces was a (my) mistake. Serializer metadata are value objects. Nobody will (nor should) implement these interfaces. Composition is better for "extending" metadata. They were not marked as `@api` and should now be marked as `@internal` (or even deprecated but it will cause some maintenance headaches). Commits ------- 3f6cfcd [Serializer] Make metadata interfaces internal
ping @symfony/deciders Would be nice to merge soon to be able to work on #16143 without creating conflicts. |
|
||
if (!is_int($data['value'])) { | ||
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an int.', get_class($this))); | ||
} |
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.
What about also checking that the value is greater than zero?
Status: needs review ping @symfony/deciders |
@@ -41,7 +41,7 @@ public function addAttributeMetadata(AttributeMetadataInterface $attributeMetada | |||
/** | |||
* Gets the list of {@link AttributeMetadataInterface}. | |||
* | |||
* @return AttributeMetadataInterface[] | |||
* @return @return AttributeMetadataInterface[] |
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.
typo
Made some small comments, 👍 |
Should be ok now. |
Thank you @dunglas. |
…oNormalize (dunglas) This PR was squashed before being merged into the 3.1 branch (closes #20530). Discussion ---------- [Serializer] Remove AbstractObjectNormalizer::isAttributeToNormalize | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | unclear | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a I've introduced this method by error in #17113. It has been forgotten during a refactoring. It has always been unused, is not covered by our test suite and has never been documented. Technically it's a BC break (because this is a protected method), but I think that it's better to remove it has it has never be intended to be used, it's just a miss. An alternative is to deprecate it and remove it in v4. Commits ------- fea18aa [Serializer] Remove AbstractObjectNormalizer::isAttributeToNormalize
…, javiereguiluz) This PR was merged into the 3.1 branch. Discussion ---------- [Serializer] Docs for the @MaxDepth annotation Docs for symfony/symfony#17113. Commits ------- d7395d3 Make lines shorter to comply with our soft limit of 80 chars per line 93dcc3f Fix comments 97f48e5 [Serializer] Docs for the @MaxDepth annotation
Add a max depth option during the normalization process. Especially useful when normalizing trees.
Usage:
@MaxDepth(2)
annotation and loader/cc @mRoca @csarrazi