-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] FromQuery, FromBody, FromRoute, etc. attributes #58709
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
base: 7.3
Are you sure you want to change the base?
Conversation
Thank you. Please apply the patch from fabbot to fix all code-style issues. |
@@ -31,6 +33,8 @@ | |||
*/ | |||
final class EntityValueResolver implements ValueResolverInterface | |||
{ | |||
use ValueBagResolverTrait; |
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.
This change will render the Doctrine Bridge incompatible with older versions of the HttpKernel component. That's fine, but we need to tell Composer about that.
Please adjust this conflict rule:
"symfony/http-kernel": "<6.4", |
Since you're currently targeting 7.2 for this change, declaring incompatibility with versions before 7.2 would solve the problem.
@@ -122,7 +128,7 @@ private function find(ObjectManager $manager, Request $request, MapEntity $optio | |||
} | |||
} | |||
|
|||
private function getIdentifier(Request $request, MapEntity $options, ArgumentMetadata $argument): mixed | |||
private function getIdentifier(Request $request, MapEntity $options, ArgumentMetadata $argument, ParameterBag $valueBag): mixed |
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.
As far as I can tell, the $valueBag
parameter has effectively replaced the $request
in most private methods you've touched here. Let's remove the now-unused parameter where we can.
private function getIdentifier(Request $request, MapEntity $options, ArgumentMetadata $argument, ParameterBag $valueBag): mixed | |
private function getIdentifier(ParameterBag $valueBag, MapEntity $options, ArgumentMetadata $argument): mixed |
public function testVariadicEnum() | ||
{ | ||
// TODO | ||
} | ||
|
||
public function testVariadicUid() | ||
{ | ||
// TODO | ||
} | ||
|
||
public function testVariadicDateTime() | ||
{ | ||
// TODO | ||
} |
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.
🙃
I'd prefer |
Thank you all for comments.
General idea is to decouple #[From..] attributes from #[Map...] attributes, so in order to do it, I needed to make ValueResolvers for Entity, DateTime, Uid and other unaware of any #[From..] attributes. That is why they just receive a $valueBag ready for them to consume values from. In latest commit I addressed the compatibility with variadic parameters. Now any ValueResolver work with variadic and non-variadic parameters the same way. They just being called Due to this, we no longer need Also, I think this PR is finalized in my point of view. There are couple things I'm not still very happy about:
The thing I am happy about is that any custom ValueResolver can be converted with just a few lines of code. |
…st parameter bag to use
ef7e5e4
to
9e5b4ff
Compare
This is an attempt to separate how and from where the controller arguments are resolved.
Proposed new attributes
#[FromQuery]
#[FromBody]
#[FromRoute]
and#[FromHeader]
(ValueBagResolver
s) can be used in conjunction with existing#[MapDateTime]
or#[MapEntity]
.Most ValueResolvers that use data from request currently use only
$request->attributes
bag. They are easily converted to work with another bag specified by attribute by usingValueBagResolverTrait
. BC is kept: when no argument attributes specified,$request->attributes
is used.It can deprecate
#[MapQueryParameter]
.It may deprecate
#[MapQueryString]
and#[MapRequestPayload]
in the future, but it will need a something like#[MapDto]
to replace them.Currently I'm not quite done with handling variadic parameters. I want BackedEnum, Uid, and DateTime values to be supported, but I don't feel like their respective ValueResovlers should handle both variadic and non-variadic logic. On the other side, VariadicValueResolver has no ability to subsequently resolve values.
Feedback much appreciated.
Example: