Commit 6f598f9
committed
feature symfony#59904 [Routing] Add alias in
This PR was squashed before being merged into the 7.3 branch.
Discussion
----------
[Routing] Add alias in `{foo:bar}` syntax in route parameter
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| License | MIT
Since symfony#54720 we can/have to write route parameters with "destination" as slug:bar,
but if we have two properties with same name example :
`/search-book/{name:author}/{name:category}`
we get the error message : Route pattern "/search-book/{name}/{name}" cannot reference variable name "name" more than once.
Actually to prevent this error we have to use MapEntity as :
```php
public function bookSearch(
#[MapEntity(mapping: ['authorName' => 'name'])]
Author $author,
#[MapEntity(mapping: ['categoryName' => 'name'])]
Category $category): Response
{
```
and we have to remove Mapped Route Parameters :
`#[Route('/search-book/{authorName}/{categoryName}')`
This PR proposal is to remove MapEntity attributes and keep Mapped Route Parameters by adding an alias on it :
`/search-book/{authorName:author.name}/{categoryName:category.name}`
With that, EntityValueResolver will search name in author Entity and name in Category Entity.
We can have url with : `{{ path('bookSearch', {authorName: 'KING', categoryName: 'Horror'}) }}`
Commits
-------
4e2c638 [Routing] Add alias in `{foo:bar}` syntax in route parameter{foo:bar} syntax in route parameter (eltharin)File tree
4 files changed
+83
-9
lines changed- src/Symfony/Component
- HttpKernel
- EventListener
- Tests/EventListener
- Routing
- Tests/Matcher
4 files changed
+83
-9
lines changedLines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
121 | 128 | | |
122 | 129 | | |
123 | 130 | | |
| |||
Lines changed: 44 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
326 | 370 | | |
327 | 371 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | | - | |
422 | | - | |
423 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
424 | 424 | | |
425 | | - | |
426 | | - | |
| 425 | + | |
| 426 | + | |
427 | 427 | | |
428 | | - | |
429 | | - | |
| 428 | + | |
| 429 | + | |
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| |||
Lines changed: 24 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1011 | 1011 | | |
1012 | 1012 | | |
1013 | 1013 | | |
1014 | | - | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
1015 | 1038 | | |
1016 | 1039 | | |
1017 | 1040 | | |
| |||
0 commit comments