-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle][DX] Improving the redirect config when using RedirectController #33217
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
Conversation
6ce11cc
to
93e69ea
Compare
src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
Outdated
Show resolved
Hide resolved
93e69ea
to
bea281d
Compare
👍 What about deprecating the other two methods? (in favor of making them private/protected in Symfony 5.0) |
I don't think deprecating is worth the trouble it will put on users. |
From a DX perspective, this would be really amazing if we could make something like this: # config/routes.yaml
doc_shortcut:
path: /doc
controller: RedirectController
defaults:
route: 'doc_page'
legacy_doc:
path: /legacy/doc
controller: RedirectController
defaults:
path: 'https://legacy.example.com/doc' Or perhaps: # config/routes.yaml
doc_shortcut:
path: /doc
redirect:
route: 'doc_page'
legacy_doc:
path: /legacy/doc
redirect:
path: 'https://legacy.example.com/doc' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should throw also when both settings are defined at the same time.
src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php
Show resolved
Hide resolved
bea281d
to
deada37
Compare
src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
Outdated
Show resolved
Hide resolved
throw new \RuntimeException('Ambiguous redirection settings, use the "path" or "route" parameter, not both.'); | ||
} | ||
|
||
return $this->redirectAction($request, $p['route'], $p['permanent'] ?? false, $p['ignoreAttributes'] ?? false, $p['keepRequestMethod'] ?? false, $p['keepQueryParams'] ?? false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for all the common parameters, you could make them arguments of the controller instead, to let Symfony bind them (with any logic applied by argument resolver, as done for other methods) and take the default values from the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's worth it just for two common parameters.
src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
Outdated
Show resolved
Hide resolved
2ee8baf
to
33fd9b0
Compare
src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
Outdated
Show resolved
Hide resolved
33fd9b0
to
cb3cafa
Compare
cb3cafa
to
0ebb469
Compare
…en using RedirectController (yceruto) This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle][DX] Improving the redirect config when using RedirectController | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | symfony/symfony-docs#12189 follow-up #24637 **Before:** ```yaml # config/routes.yaml doc_shortcut: path: /doc controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction defaults: route: 'doc_page' legacy_doc: path: /legacy/doc controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction defaults: path: 'https://legacy.example.com/doc' ``` **After:** ```yaml # config/routes.yaml doc_shortcut: path: /doc controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController defaults: route: 'doc_page' legacy_doc: path: /legacy/doc controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController defaults: path: 'https://legacy.example.com/doc' ``` See more before/after configs (XML, PHP) in doc PR symfony/symfony-docs#12189 Commits ------- 0ebb469 Improving redirect config when using RedirectController
…ng RedirectController (yceruto) This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle][DX] Improving redirect config when using RedirectController Update according to symfony/symfony#33217 Commits ------- f59c61f [DX] Improving redirect config
follow-up #24637
Before:
After:
See more before/after configs (XML, PHP) in doc PR symfony/symfony-docs#12189