-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add ->hasCacheableSupportsMethod() to CacheableSupportsMethodInterface #27105
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
It's really weird for an interface called |
6e2a792
to
0129e98
Compare
@teohhanhui why not a new name indeed. Do you have a suggestion? Naming is hard :) About a separate interface, I don't understand what you're suggesting. One interface is enough, isn't it? |
@nicolas-grekas Apart from the typo ( What is your aim here? Should I implement this interface in my normalizers and return |
What does "doesn't work" mean? My aim it at making the cacheable mechanism BC, by making it opt-in. |
It means, my normalizers are still not used and serialization falls back to |
@emodric I fail to understand why. Can you debug the situation after applying this PR please? |
Can’t we mark |
I'll try. Give me a couple of days. |
I think there's a much simpler and BC-safe way of doing this. Have subclasses of the built-in normalizers that implement the new interface. Then it's truly opt-in and has no potential of any BC breaks. |
And we could of course use them by default in the declared services. |
@teohhanhui we had this idea, but it only fixes the problem when using the component directly. |
@emodric can you provide the code of your custom normalizer (even privately, using a private Gist for instance, or PM on Slack)? Does it extend a builtin normalizer, or the |
I'm not near a computer today, but as soon as I'm back, I'll do it. I'll try to create a test app to provoke the issue, too. In the meantime, my normalizers implement
|
How so? Liskov Substitution Principle means we can substitute them with any subclasses any time, no? |
@teohhanhui what is not truly opt-in in the current PR? Also, where is the potential BC break? Please advise I don't understand. Also, how would you handle the ArrayNormalizer case (see attached patch for the way this PR does it?) Would you mind opening a PR embedding your proposal? It might be easier to understand each other this way. Thanks. |
Unfortunately we cannot rely on it to replace Symfony native services. If the user uses |
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 understand the reluctance for such thing but don't see any better way to solve the problem)
That really is the fault of the client code, or does the Symfony BC promise even cover that? :x |
@dunglas Here's a Symfony Standard app (it was easier to setup this way, rather than using Flex) with @nicolas-grekas Run the app with the built in server with The output is |
@emodric thanks for the reproducer, it definitely helped, this is now fixed! |
$this->normalizerCache[$format][$type][$k] = false; | ||
} elseif ($normalizer->supportsNormalization($data, $format)) { | ||
$this->normalizerCache[$format][$type][$k] = true; | ||
|
||
return $normalizer; | ||
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.
This was the bug spotted by @emodric: we cannot return here, as the non-cacheable normalizers weren't checked yet.
Thanks @nicolas-grekas ! Tested it with my test suite and now it works 👍 |
What about: VarySupportsNormalizerInterface
(So that there's more granular control and we can cache separately for normalization / denormalization?) VarySupportsSerializerInterface
|
Actually, we need to add different interfaces for Normalizers and Denormalizers. |
Talking on Slack with @dunglas, here is the plan we have in mind:
This way, we have the best flexibility for all cases. About the name here, despite the proposal (thanks for it), I'd still keep this PR as is. PR ready on my side. |
The name |
Thank you @nicolas-grekas. |
…heableSupportsMethodInterface (nicolas-grekas) This PR was merged into the 4.1-dev branch. Discussion ---------- [Serializer] Add ->hasCacheableSupportsMethod() to CacheableSupportsMethodInterface | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Enhances the interface introduced in #27049 to make it possible to dynamically define if "supports" methods are cacheable. Commits ------- 04b3692 [Serializer] Add ->hasCacheableSupportsMethod() to CacheableSupportsMethodInterface
@teohhanhui can you propose a better name in a new PR? |
Enhances the interface introduced in #27049 to make it possible to dynamically define if "supports" methods are cacheable.