-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add new normalizer: PropertyInfoNormalizer based on PropertyInfo / PropertyAccess components #30960
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
[Serializer] Add new normalizer: PropertyInfoNormalizer based on PropertyInfo / PropertyAccess components #30960
Conversation
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.
Very promising!
|
||
private $objectClassResolver; | ||
|
||
public function __construct($instantiator, ObjectPropertyListExtractor $normalizerExtractor, PropertyListExtractorInterface $denormalizerExtractor, PropertyAccessorInterface $propertyAccessor, AdvancedNameConverterInterface $nameConverter = null, callable $objectClassReolver = null) |
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.
We should allow to pass the standard NameConverterInterface here (and pass the extra argument required for the advanced one).
public function normalize($object, $format = null, array $context = []) | ||
{ | ||
$properties = $this->normalizerExtractor->getProperties($object, $context); | ||
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object); |
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 we deal with Doctrine proxies here?
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.
That's what we do isn't it ?
Allowing an object class resolver will allow to inject a specific callback to handle this problem.
What is the status of this PR? @joelwurtz could you finish this or leave a comment to help others taking over this PR? |
This PR need the advancement of all points present in #30818 as it will use all interface / implementations make on those differents PR to create this new normalizer |
$propertyName = $this->nameConverter ? $this->nameConverter->normalize($property, $class, $format, $context) : $property; | ||
$value = $this->propertyAccessor->getValue($object, $property); | ||
|
||
if (!is_scalar($value)) { |
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'd add null !== $value &&
before to save some iterations, wdyt?
We've just moved away from |
This add the new Normalizer, as a Draft as we don't have all the building blocks actually, to show how we want to resolve things.
Will update this PR on the course of others advancement for #30818