-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add a more global interface with all method implement by the implemantation #43325
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
Comments
What's the usecase? |
avoid this (or avoid ignoring phpstan error) |
Understood. I meant what usecase requires all 3 services? Generally I'd prefer wiring an intersection type, rather than introducing a new one. |
I don't think the DI component supports intersection types yet for autowiring. @nicolas-grekas can you confirm ? |
it doesn't, we never thought about it yet |
you are right, it's not common for all interfaces, but normalizer + denormalizer is common to me. Think about the layer between your data (POPO) and Elasticsearch. You want to normalizer before sending to ES, then denormalize when getting the data back. We can generalize the use case: it occurs when you want to use the serializer to format the data you send / get from a database (or API, you get the point:) ) You could say: Why not using serialize / deserialize directly: some time, the lib does the json_encode / json_decode on his side. |
+1 for combining normalizers with its counter denormalize part AFAIK it's the common case: |
What would be the name of the interface ? |
i'd opt for deprecating DenormalizerInterface, favoring NormalizerInterface. But Maybe intersection support in DI is sufficient ... |
Actually, I don't what to do
|
Then a new type 🤷 |
But I can not find a name :/ |
to me normalization comes with de-normalization, hence i think NormalizerDenormalizeInterface i've no opinion what would be more annoying, a new symbol vs a new method. The latter seems better to discover 🤷 |
I propose #43479 to fix this issue. |
…types (nicolas-grekas) This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] autowire union and intersection types | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #43325 | License | MIT | Doc PR | - This PR allows autowiring an argument of type `NormalizerInterface&DenormalizerInterface` if both individual types have a corresponding autowiring alias, and if both aliases point to the very same service. This works the same with union types. Commits ------- aba31f9 [DependencyInjection] autowire union and intersection types
#43479 is merged, agree to close this one? |
Sure 👍🏼 it'll totally fix my issue. thanks @nicolas-grekas |
It's very common in a service to inject the normalizer, and to use
normalize()
ordenormalize()
However, theses methods does not exist on
SerializerInterface
.So, if we want to use
normalize()
,denormalize()
, andserializer
,we need to inject 3 services: NormalizerInterface, DenormalizerInterface, and SerializerInterface. Not really handy !To be honest, I always inject the SerializerInterface, because I know methods exists on the implementations. But on every projects, I have to ignore error reported by static analysis.
So, what do you think of creating an interface that embrace all three others?
Side question, with PHP 8.1 we have intersection types, how does behave the containers with the following signature
The text was updated successfully, but these errors were encountered: