Skip to content
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

[Routing] Add {foo:bar} syntax to define a mapping between a route parameter and its corresponding request attribute #19869

Open
wants to merge 3 commits into
base: 7.1
Choose a base branch
from

Conversation

alamirault
Copy link
Contributor

Fix #19846

…rameter and its corresponding request attribute
routing.rst Outdated Show resolved Hide resolved
routing.rst Outdated Show resolved Hide resolved
routing.rst Outdated Show resolved Hide resolved
Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
@alamirault alamirault requested a review from OskarStark May 8, 2024 08:27
Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Antoine, thanks for this contribution!

routing.rst Outdated Show resolved Hide resolved
routing.rst Outdated Show resolved Hide resolved
routing.rst Outdated Show resolved Hide resolved
routing.rst Outdated Show resolved Hide resolved
@rcsofttech85
Copy link
Contributor

rcsofttech85 commented May 8, 2024

I did not find any example on map entity, you may consider this example below

    #[Route(path: '/profile/{name:name}/{age:age}', name: 'profile', methods: ['GET'])]
    public function fetchProfile(Profile $profile): Response
    {
       // 

    }

@alamirault
Copy link
Contributor Author

I did not find any example on map entity, you may consider this example below

    #[Route(path: '/profile/{name:name}/{age:age}', name: 'profile', methods: ['GET'])]
    public function fetchProfile(Profile $profile): Response
    {
       // 

    }

I'm not sure to understand your suggestion, why map name to name and age to age ?

I think the original PR has no direct link with MapEntity ?

@rcsofttech85
Copy link
Contributor

@alamirault The main idea was to improve automapping doctrine entities. Now, automapping of entities in favor of mapped route parameters is deprecated. The code I posted is a working example of entities and route parameters.

{name:name}/{age:age} = > "foo" is the name of the wildcard and "bar" is a property or attribute of the entity.

Here is another simple example:

    #[Route(path: '/product/{product_slug:slug}', name: 'product', methods: ['GET'])]
    public function getProduct(Product $product): Response
    {
       // 

    }

@nicolas-grekas could you please ensure it's correct.

~~~~~~~~~~~~~~~~~~

By default, the route parameter (``{slug}`` for example) is the name of the argument
injected to the controller method (``$slug``).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to be more precise. There are two steps between parameters and controllers:
The routing side does only one thing: populate a parameter named _route_mapping.
Then a listener will use that to map parameters to request attributes.
And then argument resolvers will map to controllers.
Explaining the steps can empower readers.
Not sure what exactly how we should say all this :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info. I just wanted to help with the code which works with this new feature.. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Routing] Add {foo:bar} syntax to define a mapping between a route pa…
6 participants