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
Support backed enums in #[MapQueryParameter]
#50910
Comments
@kells64000 if (!is_a($argument->getType(), \DateTimeInterface::class, true) || !$request->attributes->has($argument->getName())) {
return [];
} So I would consider this as feature, not as a bug. The question is whether this feature is needed or not. |
I agree that this is a new feature. And it makes total sense to support enums here. Do you want to wirk on a PR? |
@derrabus |
#[MapQueryParameter]
It was a bug for me because why can I use any resolver if none of them looks at the query parameters? |
Only |
…ter]` (andersmateusz) This PR was merged into the 6.4 branch. Discussion ---------- [HttpKernel] Support backed enums in `#[MapQueryParameter]` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #50910 | License | MIT | Doc PR | I think documentation about MapQueryParameter is missing I had two options to introduce this feature. Extending `QueryParameterValueResolver` or extending `BackedEnumValueResolver`. Both options have it's prons and cons. Extending `QueryParameterValueResolver` is not consistent with DRY principle, but on the other hand does not mislead users about usage of `ValueResolverInterface` (`#[MapQueryParameter]`takes `resolver` argument but only `QueryParameterValueResolver` resolves value unless creating your own implementation of the interface). I have chosen to extend `QueryParameterValueResolver`. I think in the future separation of concerns should be introduced (resolving query params, resolving attributes etc.). For example by typing resolvers with new interface and using intersection types. Commits ------- 487f5f8 [HttpKernel] Support backed enums in #[MapQueryParameter]
Symfony version(s) affected
6.3.1
Description
If you use #[MapQueryParameter] and type the property with Enum, the QueryParameterValueResolver only accepts scalars.
If I change the resolver to BackedEnumValueResolver, it only looks at the attributes and not the query.
The enum is never resolved and the value is null.
How to reproduce
Controller:
OR
Enum:
Query:
Possible Solution
Additional Context
No response
The text was updated successfully, but these errors were encountered: