-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Open
Description
Symfony version(s) affected
7.1.5
Description
You may want to map request data to a DTO and then pass that DTO object to a VoterInterface
. However, this is impossible because the IsGrantedAttributeListener
is called before the RequestPayloadValueResolver
event subscriber.
The resolved DTO object is expected by the Voter
, but the MapQueryString
instance is passed.
How to reproduce
- Create any DTO class you want to map from a request data.
- Create a
Voter
that accepts the DTO class. - Add the IsGranted attribute to a controller and set the subject to the mapped variable like so
#[IsGranted('post_create', 'post' )]
- The
Voter
expects thePostDto
instance as a subject, but gets theMapQueryString
instance.
#[IsGranted('post_create', 'post')]
#[Route('/post, name: "app_post")]
public function post(
#[MapQueryString] PostDto $post,
): Response
{
return new Response('OK');
}
Possible Solution
Explicitly set higher priority for the RequestPayloadValueResolver
. It should be triggered right before the IsGrantedAttributeListener
.
class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER_ARGUMENTS => ['onKernelControllerArguments', 21],
];
}
}
Additional Context
No response