Remove final constructor for Type#6705
Conversation
|
Note: this is another take on #5528 |
|
I've never used custom types as besides schema management, they are primarily designed for the ORM. I'll defer to Alexander. |
|
If we do that, we turn |
How will it be a potential footgun? The current desired behavior is guarded, so I don't see how.
I agree, but that can be done independently from this PR, no? |
Yes, you've done all you could to give the developer proper feedback. Yet, we're about to create a class of types that cannot be registered with
Sure, but still we should talk about it. We somehow ended up with an only partially implemented feature and I want us to work towards a proper solution this time instead of adding a small hack on top to make it somewhat work. |
e6b5c83 to
355887c
Compare
greg0ire
left a comment
There was a problem hiding this comment.
It seems the tests I wrote in my initial PR were not sufficient to prove it's possible to do what's in the documentation. Maybe they should be improved?
UPGRADE.md
Outdated
|
|
||
| ## Deprecated Type::addType | ||
|
|
||
| Use Type::getTypeRegistry()->register() instead. |
There was a problem hiding this comment.
| Use Type::getTypeRegistry()->register() instead. | |
| Use `Type::getTypeRegistry()->register()` instead. |
|
The docs should be updated, they mention |
2c1e7df to
b3b1dac
Compare
|
@greg0ire I made some changes. Could you approve the workflow so we can see the test results? |
GromNaN
left a comment
There was a problem hiding this comment.
Added some suggestion to keep the API consistent.
Injecting the TypeRegistry everywhere might be a long-term project that involves a lot of changes in other Doctrine packages.
src/Types/Type.php
Outdated
| * | ||
| * @deprecated Use Type::getTypeRegistry()->register() instead. | ||
| */ | ||
| public static function addType(string $name, string $className): void |
There was a problem hiding this comment.
We could keep this method if the arg type were widened.
| public static function addType(string $name, string $className): void | |
| public static function addType(string $name, string|Type $type): void |
Either we keep this API, or we deprecate all the static methods of this class (getType, hasType, lookupName, overrideType, getTypesMap), which would have a large impact on the Doctrine related packages.
If you don't want to change the signature of this method, you can add setType(string $name, Type $type, bool $override = false).
Note that the DoctrineBundle would use the optional "override" in ConnectionFactory.
There was a problem hiding this comment.
I like it, I pushed the changes. Much simpler now!
| } | ||
|
|
||
| Type::addType(MoneyType::NAME, MoneyType::class); | ||
| Type::getTypeRegistry()->register(MoneyType::NAME, new MoneyType); |
There was a problem hiding this comment.
The API could be as simple as this:
| Type::getTypeRegistry()->register(MoneyType::NAME, new MoneyType); | |
| Type::addType(MoneyType::NAME, new MoneyType()); |
e466fd8 to
f9917a1
Compare
GromNaN
left a comment
There was a problem hiding this comment.
The approach seems correct at first.
Ideally, someone should take care of injecting the TypeRegistry everywhere the Type::getType() is used.
|
@GromNaN thanks, applied your feedback! |
|
@ruudk static analysis is failing |
4d5934e to
a3db335
Compare
|
@greg0ire Fixed them, please approve the workflow. |
SenseException
left a comment
There was a problem hiding this comment.
Okay, but what happened to the deprecation?
|
@SenseException See #6705 (comment). There a solution was proposed that would allow me to not deal with the depreciation. Deprecating it yes or no is now a task for the future. Not required for this feature. |
|
Thanks @ruudk ! |
|
@greg0ire Is there an ETA for 4.3.0? I see the milestone is 100%. I would really like to use this constructor 😁 |
|
Not yet, but I wouldn't want to wait too much longer either. 😃 |
|
Thank you a lot guys! This finally made it possible to register custom Doctrine types in the Symfony Container and use them from there. I can't express my gratitude for the work done! |
|
Thanks! I wish DoctrineBundle would make it a lot easier to register types as services now that this is in place. |
|
For the MongoDB ODM Bundle, I'm adding a new attribute This is something that could be done in the same way in Doctrine bundle; with a new tag and an attribute |
|
That would be amazing! |
Summary
This allows people to define a constructor when creating custom
Doctrine\DBAL\Types\Typeimplementations.They can be registered by passing an instance to
Type::addType.When a class string is passed, and the Type cannot be instantiated, an helpful error message will be thrown.