Skip to content

[DoctrineBridge] Passing the request object to the EntityValueResolver's expression #51694

@stollr

Description

@stollr

Description

I would like to suggest passing the request object to the expression evaluation of the EntityValueResolver. This would make it possible to use parameters of the request body which is useful in REST APIs.

In the resolver we only need to change the following line in the findViaExpression method:

-         $variables = array_merge($request->attributes->all(), ['repository' => $repository]);
+         $variables = array_merge($request->attributes->all(), [
+             'repository' => $repository,
+             'request' => $request,
+         ]); 

Example

Now, one could use the expression like this:

public function createAction(
    #[MapEntity(expr: 'repository.find(request.toArray()["userId"])')]
    User $user,
) {}

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions