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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy