-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection][HttpKernel] Fix enum typed bindings #44838
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedEnumArgumentDummy.php
Show resolved
Hide resolved
1d7b71e
to
c32d749
Compare
Thank you @ogizanagi. |
This was referenced Dec 29, 2021
Merged
Merged
Merged
Merged
Thanks @ogizanagi |
nicolas-grekas
added a commit
that referenced
this pull request
Feb 4, 2022
…num as parameters (ogizanagi) This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [DependencyInjection][FrameworkBundle] Fix using PHP 8.1 enum as parameters | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | yesish | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #44834 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | N/A While #40857 allowed using enums in DI, it does not allow using these in parameters. This would be the actual fix for #44834, which shows the error you'll get trying to use enum as DI parameters (appart from the binding issue fixed in #44838):  given: ```php namespace App; enum Status { case Draft; case Deleted; case Published; } ``` ```yaml # services.yaml parameters: default_status: !php/const App\Status::Draft ``` The exception happens because the `PhpDumper` misses the leading slash: ```diff protected function getDefaultParameters(): array { return [ - 'default_status' => App\Status::Draft, + 'default_status' => \App\Status::Draft, ]; } ``` While this would fix using enums as DI parameters as of Symfony < 6, the `ParameterBagInterface::get/set` and `ContainerInterface::setParameter/getParameter` are not allowing `\UnitEnum` and adding these in phpdoc is an issue since actual typehints and return types were added as of Symfony 6. => So this PR is a BC break, but hopefully nobody will be hit by it 🤞🏻 (poke `@ismail1432` - https://twitter.com/SmaineDev/status/1476237072826613763?s=20) Commits ------- ac36617 [DependencyInjection][FrameworkBundle] Fix using PHP 8.1 enum as parameters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to #44834
While:
is working for me, the following isn't:
->
This attempts to fix it by accounting for
\UnitEnum
in theResolveBindingPass
,as well as re-allowing enum types already present in bindings after #44826.