-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add support for polymorphic types #5147
Conversation
Related: #4930 |
Hi! Thanks for working on this! This is clever, but maybe not in a good way: I had a hard time understanding your PR, and I think if somebody asks me to explain it tomorrow, I will have a hard time too… My idea was to have #5036 + something to make it easier to register types for each enum people have to make this more straightforward, and then have such mapping : In your proposal, if an object implements 2 interfaces, and both interfaces map to a different type, and both types are polymorphic, the first one wins. Obviously this is not meant to happen and is unlikely to, but if feels like a hack designed because it will work with enums as opposed to something generic that could be used to implement something else like the encrypted type showcased in #5036 |
Also, regarding enums, we have this proposal at the ORM level: doctrine/orm#9304 |
Yes, the first motivation behind this PR was to implement Enum type. So maybe if it drops generic class/enum inheritance and supports only enums it would be both better to understand and without class type inheritance ambiguity? I agree that a proper DI for types which would enable setting up any object type instance is the proper solution for other use cases (encryption, etc.). ORM level for Enum is fine but I don't think that from ORM point of view the column is of a type string/int. It is Enum type and the string/int is just an implementation detail. That's one of the reasons I think dbal is a better place for implementing Enum types. PS: I'm getting lost in this too. ;) I think what makes it harder to understand is that there are two "types": 1. type NAME 2. type IMPLEMENTATION. Type name used to be non FQCN string (like "json", "object", "int", etc.). This PR works with FQCN as NAME and then uses class inheritance as NAME inheritance. For example: BackedEnum => Role or App\Entity\Thing => App\Entity\Car. Then, once IMPLEMENTATION is registered for a parent NAME it is shared with all NAMEs (and each IMPLEMENTATION knows about a specific NAME).
|
Let's see where the ORM PR goes, OK? It's very promising and if your end goal is to have enum support, it should make you happy :) |
It got merged, let's close! |
Summary
The idea is to use FQCN as type name. Let's have
Foo\Child extends Foo\Parent
and register Foo\Parent typeType::addType('Foo\Parent', SomeType::class)
. Then TypeRegistry would automatically register SomeType::class also for Foo\Child type. SomeType would also know whether it handles Foo\Child or Foo\Parent value.Example (Enum type implementation)