-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[MapRequestPayload] Allow usage of expressions for defining validation groups #58273
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.4
Are you sure you want to change the base?
[MapRequestPayload] Allow usage of expressions for defining validation groups #58273
Conversation
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.
LGTM, here are some minor comments
src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php
Outdated
Show resolved
Hide resolved
->set('controller.expression_language', ExpressionLanguage::class) | ||
->args([service('cache.request_payload_value_resolver_expression_language')->nullOnInvalid()]) | ||
|
||
->set('cache.request_payload_value_resolver_expression_language') |
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.
either the EL service is named like proposed and this needs to ba aligned, or we change the name of the EL service, but the current mix looks inconsistent to me
->set('cache.request_payload_value_resolver_expression_language') | |
->set('cache.controller_expression_language') |
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.
@nicolas-grekas true. i prefer suggested change.
fixed 550c8a4
34d63e6
to
4af5a37
Compare
4af5a37
to
14189d2
Compare
5ebb49b
to
1f9de26
Compare
1f9de26
to
29d53f3
Compare
29d53f3
to
85204a5
Compare
It looks like your committer email is not associated with your GitHub account, you may want to change that for credibility 🖖 |
@OskarStark thanks for advice, i fixed that 😄 |
…equestPayloadValueResolver.php Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
…equestPayloadValueResolver.php Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
85204a5
to
67eb8ec
Compare
This PR adds option to use Expression for defining validation groups when using
#[MapRequestPayload]
and#[MapQueryString]
Inspired by expression options when using
#[IsGranted]
, request and args are available.Example:
We have route which is used to update user info. Entity
User
has propertytype
which can beadmin
orregular
.If user is admin, his password must be very strong and they must have image while regular user can have weaker password and image is not required.
Payload used in request:
We need to dynamically determine which validation group to use based on context (User that is being updated).
Current way of doing this is to manually call
validate
method:This PR allows usage of Expression with access to arguments so above code can be replaced with
#[MapRequestPayload]