-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #54720 [Routing] Add
{foo:bar}
syntax to define a mapping b…
…etween a route parameter and its corresponding request attribute (nicolas-grekas) This PR was merged into the 7.1 branch. Discussion ---------- [Routing] Add `{foo:bar}` syntax to define a mapping between a route parameter and its corresponding request attribute | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT While trying to improve the DX of auto-mapping Doctrine entities and from the discussion on the related PR #54455, I realized that it would help a lot if we were able to express a mapping between route parameter and request attributes directly into route definitions. This PR adds the ability to define a route with such a mapping: ```php #[Route('/conference/{slug:conference}')] ``` On the router side, the side-effect of this is just that a new `_route_mapping` array is returned by the matcher, and nothing else. Then, in HttpKernel's RouterListener, we use that parameter to map route parameters to request attributes. On their turn, argument resolvers will just see a request attribute named `conference`. But they can also now read the `_route_mapping` attribute and decide to do more tailored things depending on the mapping. For example, one could define this route: ```php #[Route('/conference/{id:conference}/{slug:conference}')] ``` This would be turned into a request attribute named `conference` with `['id' => 'the-id', 'slug' => 'the-slug']` as content. This mapping concern already leaks into many value resolver attributes (see their "name" property). For the entity value resolver, this feature will allow deprecating auto-mapping altogether, and will make things more explicit. Commits ------- 1e091b9 [Routing] Add `{foo:bar}` syntax to define a mapping between a route parameter and its corresponding request attribute
- Loading branch information
Showing
6 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters