-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add PropertyValueNormalizer to AbstractObjectNormalizer for code reusability with composition #46662
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
base: 7.4
Are you sure you want to change the base?
Conversation
@@ -441,135 +686,63 @@ abstract protected function setAttributeValue(object $object, string $attribute, | |||
* @throws NotNormalizableValueException | |||
* @throws LogicException | |||
*/ | |||
private function validateAndDenormalize(array $types, string $currentClass, string $attribute, mixed $data, ?string $format, array $context): mixed | |||
protected function validateAndDenormalize(array $types, string $currentClass, string $attribute, mixed $data, ?string $format, array $context): mixed |
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 method is made protected because it is used line 392. This allows overriding only the nested properties denormalization logic, and only part of it by using all previous methods provided.
cda47e5
to
7bbaab9
Compare
* | ||
* This function is not meant to be overriden, only used. If you might want to override validateAndDenormalize. | ||
*/ | ||
final protected function isNullDenormalization(Type $type, string $currentClass, string $attribute, mixed $data, ?string $format, array &$context): bool |
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.
These functions always receive the same set of arguments in order to stay coherent and help developping. But you might want not to?
Making things protected has a huge impact in term of maintenance, because inheritance-based extension points are the ones for which it is harder to write a BC layer. |
Sure! Will try to this is as soon as I can. |
For the record there is an ongoing (yet slow) work to move from inheritance to composition in the Serializer component. So I agree with @stof, it would be better to move this work forward instead of opening more methods. |
12dfe3d
to
7ff98ea
Compare
23b3904
to
df02d70
Compare
… for code reusability
df02d70
to
816eddf
Compare
As stated in #46649, I would like to enable
AbstractObjetNormalizer
code resuable to child without having to rewrite all the logic and maintain it. This would also avoid using trick to normalize differently some properties, as it is done by ApiPlatform here and here.I have made comments on my PR to explain some changes.
Please let me know if it needs some changes.