Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpKernel] Do not attempt to register enum arguments in controller service locator#44826

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@ogizanagi
Copy link
Contributor

@ogizanagiogizanagi commentedDec 28, 2021
edited
Loading

QA
Branch?4.4
Bug fix?yes
New feature?no
Deprecations?no
TicketsN/A
LicenseMIT
Doc PRN/A

Given:

namespaceApp\Model;enum Suit:string {case Hearts ='H';case Diamonds ='D';case Clubs ='C';case Spades ='S';}

and the controller:

class FooControllerextends AbstractController{    #[Route('/foo')]publicfunctionfoo(Suit$suit = Suit::Hearts):Response    {dd($suit);    }}

you get:

Cannot autowire argument$suit of"App\Controller\FooController::foo()": it referencesclass"App\Model\Suit" but no such service exists.in vendor/symfony/dependency-injection/Container.php (line416)in vendor/symfony/dependency-injection/Argument/ServiceLocator.php ->getService (line42)in vendor/symfony/http-kernel/Controller/ArgumentResolver/ServiceValueResolver.php ->get (line84)

which would be annoying in case you have a resolver registered to resolve this argument, but won't support this specific request, hence expect to let theDefaultValueResolver use the default value (or another resolver to try).
Currently, theDefaultValueResolver wouldn't be reached since theServiceValueResolver would throw the above exception.

@ogizanagiogizanagiforce-pushed theservice-value-resolver-enum branch from33e16e2 to89232eeCompareDecember 28, 2021 14:26
@nicolas-grekas
Copy link
Member

Thank you@ogizanagi.

@nicolas-grekasnicolas-grekas merged commitc1c6687 intosymfony:4.4Dec 28, 2021
@ogizanagiogizanagi deleted the service-value-resolver-enum branchDecember 28, 2021 14:43
nicolas-grekas added a commit that referenced this pull requestDec 29, 2021
…(ogizanagi)This PR was merged into the 4.4 branch.Discussion----------[DependencyInjection][HttpKernel] Fix enum typed bindings| Q             | A| ------------- | ---| Branch?       | 4.4 <!-- see below -->| Bug fix?      | yes| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tickets       | N/A <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->| License       | MIT| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->Relates to#44834While:```yml# services.yamlservices:    _defaults:        autowire: true        autoconfigure: true        bind:            $myParam: !php/const App\Status::Deleted```is working for me, the following isn't:```diff# services.yamlservices:    _defaults:        autowire: true        autoconfigure: true        bind:-            $myParam: !php/const App\Status::Deleted+            App\Status $myParam: !php/const App\Status::Deleted```->> Invalid value for binding key "App\Status $myParam" for service […]: expected "Symfony\Component\DependencyInjection\Reference", "Symfony\Component\DependencyInjection\Definition", "Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument", "Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument" or null, "App\Status" given.This attempts to fix it by accounting for `\UnitEnum` in the `ResolveBindingPass`,as well as re-allowing enum types already present in bindings after#44826.Commits-------c32d749 [DependencyInjection][HttpKernel] Fix enum typed bindings
This was referencedDec 29, 2021
ogizanagi added a commit to Elao/PhpEnums that referenced this pull requestDec 30, 2021
…ed enums (ogizanagi)This PR was squashed before being merged into the 2.x-dev branch.Discussion----------[HttpKernel] Add a controller argument resolver for backed enums- [x] Add tests- [x] Docs- [x] Rework to streamline the resolver with Symfony 6.1 core PR (only attributes, aims route params, 404, …) + alternative query/body resolver specific to this library.Fixed (symfony/symfony#44826):An issue with Symfony's `ServiceValueResolver` prevents from letting the `DefaultValueResolver` to use the default enum value if the argument is not nullable.Perhaps add:```php        if (enum_exists($argument->getType())) {            return false;        }```in `\Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver::supports` as a bug fix? Fix in `RegisterControllerArgumentLocatorsPass` ?Commits-------564058a Streamline with future Symfony 6.1 resolver + query/body resolvers3e04d71 [HttpKernel] Add V2 BackedEnumValueResolver to resolve controllers args
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

+1 more reviewer

@stloydstloydstloyd left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

4 participants

@ogizanagi@nicolas-grekas@stloyd@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp