-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
🚧 V2: Rewrite for PHP 8.1 Enum #124
Comments
This comment has been minimized.
This comment has been minimized.
This PR was squashed before being merged into the 2.x branch. Discussion ---------- V2: Rewrite with PHP 8.1 enums WIP POC to observe what could be relevant to keep from this lib and its integrations while moving to PHP 8.1 native enums… Relates to #124 --- #### random thoughts - [x] [WeakMap/SplObjStorage](https://wiki.php.net/rfc/enumerations#splobjectstorage_and_weakmaps) for readables? - [x] For now, no requirements for a FlaggedEnumInterface, no specific methods. But it requires an int backed enum. Drop the interface and replace by backed type reflection checks? #### notes - Enum may not include __toString (from PHP) - Cannot implement FlaggedEnum as before, since we can only define cases for each bit, but cannot hold a $value and have a FlaggedEnum instance with multiple bits. Instead, we might need a FlagBag. Will impact forms, dbal types, js generation, … - readables for Flagged enum combination might be difficult to write using the same interfaces. Dedicated system for a FlagBag? - FlagBag controller arg resolver? Commits ------- e21a5bf Update CI branches 8019e3d Update cs-fixer 5135227 Remove FlagEnumInterface & add docs 2d1c212 Complete README.md 7e1d3e4 Add Symfony Bundle & configuration for generating BDAL types e4905fb Basic doctrine dbal types dumper 2117f82 Basic Doctrine types 7db6f59 Clean the deps & CI 69f3a71 Add Symfony Form type with readable enums supports ae2bcc6 Use enum cases as keys in readables b7fa48b Base readable implem uses annotations 1633fae V2: Rewrite with PHP 8.1 enums
Tried my hands with porting the ApiPlatform bridge over. Maybe it helps?
|
Hi @jensstalder . Thank you very much for looking at this. Could you please explain me a bit more what would be the purpose of such a bridge now with native PHP enum? You might have more clues than me on what could be relevant to provide in such a bridge regarding the features that are specific to this lib v2 extending native enums capabilities. So, your help is appreciated :) |
@ogizanagi Good question. The only benefit I see in relation to JsonSchema is that it shows up in the open API docs. My original goal was to extend the graphql implementation so that the types also get interpreted as enum. I have not found a solution for that yet. But thinking about it, it's true that API platform core should instead simply handle native enums better for both cases (JsonSchema and GraphQL), and it might not be necessary to do this within this package. But this might be a bit to opinionated from the view of the platform? As far as I can tell though, API platform currently only considers the backing type as if it were a simple string or int field? And Graphql endpoint hides the enum typed field completely (but that could be another issue). |
For Doctrine there is one issue affecting this lib
Please add it on the list EDIT: merged |
@ogizanagi the doctrine/orm#9629 has been merged in doctrine/orm 2.12.x , so you can remove the known issue from the list |
First step was made in #165 to rewrite the lib with the new native enum types & adding some integrations based on it and our specificities (readables, flags, …).
📚 See current V2 documentation here
🚧 More work to come. Help welcome to integrate what could be useful, from 1.x features or whole new ones.
Will probable create a
2.0.0-alpha1
tag in the next weeks.V2 Features
Core features
From V1, core features extending the PHP 8.1 native enum capabilities
It requires a new
FlagBag
object to manipulate flags, since PHP native enums are restricted to their cases and cannot dynamically declare combinations.New features
Whole new features or integration, leveraging new enum capabilities
(Pending) official integrations
From V1, likely to be dropped in the future, or already having an official integration
Core PR: [Serializer] Support for PHP 8.1 enums symfony/symfony#40241
Doctrine is likely to provide DBAL types for enums in the future, but the current type system lacks a way to easily register it.➜ Doctrine guys found a workaround in Add support for PHP 8.1 enums. doctrine/orm#9304.
We might consider dropping our implementation, but collection and flag bag support is still valid. Also our current implementation supports specifying a default on null.
➜ Done in V2: Rewrite with PHP 8.1 enums #165. Documentation
Nothing in Symfony core yet?
no specificity for readable or flagged enum? Anything else to consider?
Core PR: PHP 8.1 Backed enums api-platform/core#4349
could be contributed to FakerPHP directly for native enum support
➜ rejected in add Enum generator FakerPHP/Faker#421.
We might only want to port
randomEnum
from V1 to get a random enum case from given enum FQCN.Porting the namespace aliases feature might not be relevant, since it was targeting Nelmio Alice's fixtures generator DSL, but Foundry is getting more popularity now.
➜ add Faker provider #177
Rejected for now in [Validator] Support enums in Choice constraints symfony/symfony#43047. Could provide the alternative here and re-discuss in Symfony's core later if proven useful.
Extra integrations
From V1, might still be relevant/adapted
Core PR: [VarDumper] add support for enums on PHP 8.1 symfony/symfony#40238)
Core PR: [Form] Add the EnumType symfony/symfony#43095
➜ Done in V2: Rewrite with PHP 8.1 enums #165. Documentation
➜ Done in FlagBagType support #183
Extra tasks
UPGRADE-2.x.md
guide, with most basic hints for upgrading your application code from 1.x to 2.xThe text was updated successfully, but these errors were encountered: