-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Detect enums and use type string (PHP 8.1 only) #9149
Conversation
Converting to draft because tests are missing.
https://phpunit.readthedocs.io/en/9.5/annotations.html#requires
I doubt that your change really solves the problem completely, but let's write some functional tests first an iterate from there. |
This commit does not contains a test because AFAIK for the moment there is no test scoped to a specific version of PHP. It fixes doctrine#9021
81abd91
to
24e29f1
Compare
@derrabus I think it's better like this indeed :) . And the rest should be inside the dbal! On it! |
{ | ||
case DRAFT; | ||
case PUBLISHED; | ||
} |
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.
Sorry for that, the current version of phpcs have issues with enums 😅 .
|
||
namespace Doctrine\Tests\Models\TypedProperties; | ||
|
||
enum ArticleStateEnum |
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.
We should support backed enums only.
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.
Why? Everything will work like this. I do not understand this limitation.
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.
Unit enums do not specify a way to convert them from or to a scalar value. This is the reason why backed enums exist in the first place.
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.
What about creating a Type for each enum type. A special serialization could be done for Unit enums making it easier to query. Maybe a json field.
I think all of this leads to more code but really seems fine to me. WDYT? (if you valid I go on this)
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.
No. If someone wants to hydrate/dehydrate enums from/to the database, they can back it with scalar values for that purpose. That's why backed enums exist.
For unbacked enums, we need a custom conversion logic and in that case, it would be easier if the developer wrote their own DBAL type for that.
Related to issue doctrine/orm#9021 Related to PR ORM doctrine/orm#9149
Related to issue doctrine/orm#9021 Related to PR ORM doctrine/orm#9149
Closing as explained in doctrine/dbal#4930. |
This is a patch for #9021 .
Edit: test added.
See doctrine/dbal#4930