-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Support subclasses of DateTime
and DateTimeImmutable
#57793
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
amcsi
commented
Jul 22, 2024
•
edited
Loading
edited
Q | A |
---|---|
Branch? | 7.2 |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
Issues | #57482 |
License | MIT |
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
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.
Thank you for your PR. However, your implementation is significantly slower than the lookup that we currently use. I don't think we should merge this change.
@derrabus I understand the need to be as fast as possible. |
Made the change. |
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
Outdated
Show resolved
Hide resolved
DateTime
and DateTimeImmutable
I don't think this is the right fix. |
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
Outdated
Show resolved
Hide resolved
@stof Literally my first implementation was changing the I could potentially cache each result if I remove the context support for supported types that I added, but then I would be concerned about memory leaks (the supported-types true/false values array keeping on getting bigger and bigger). I'm not sure the performance would be overall better, though. This first checking the supported types from the |
@stof has a point with regards to the cachability of the normalizer. I think, we should not use the context for this piece of configuration. We could inject the list of supported classes via the constructor. This way, it is set once when we build the serializer and the decisions of the voter become cacheable again. |
@derrabus, ok, then I'll change the behavior to make the list of supported classes configurable in the constructor, but use a separate property from the context's to store/read them. |
@derrabus Done. Note that I made the |
having a slower |
and no need for a caching in DateTimeNormalizer: we already have caching in Serializer |
@stof you need to come to some agreement with @derrabus, because he didn't like it when I wrote it to the way you are suggesting.
|
why that ? The But indeed, keeping the |
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php
Outdated
Show resolved
Hide resolved
What is your actual proposal @stof? Maybe I did not fully understand what you'd like to be changed. |
@derrabus always supporting all subtypes of DateTimeInterface, by making The only reason denormalization does not support subclasses is because The implementation could be |
And the cache warmup via |
@derrabus Note that the implementation of |
Alright, I've added the simplified |
@amcsi your suggested commit removing the constant is broken. It does not return the right array structure. |
@stof what do you mean? here are the square brackets. |
The returned array is supposed to be keyed by the supported classes. You however return them as values. |
@derrabus damn, I totally forgot. But you did approve, so I'm assuming my intended additional change is not needed. |
I think, we're good. 🙂 |
be3d498
to
1225eb7
Compare
Thank you @amcsi. |