-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Add a controller to send simple HTTP responses #30514
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
Wow! I can add this to #30501 <3, WDYT? |
@HeahDude while writing the PR description, I was telling myself that the full namespaces where not user friendly! Your PR looks like the missing part, it would be awesome if you add support for this new controller! |
Two quick questions:
Thanks. |
It creates a dependency to Twig (not wanted in case of an API), and requires the user to create one extra file.
I think that's a common use case:
|
If this is accepted ... I suggest to rename |
What about |
another one: |
👍 for StaticController |
For what it worth, I don't really like it because I like when everything is declared in one place. That why I even do this for "security controller": /**
* @Route("/logout", name="logout")
*/
public function logout()
{
throw new \BadMethodCallException('The security layer should handle this route.');
} |
@lyrixx your example doesn't work for |
@dunglas This particular example is not really related with your use case. It's just an explanation on why I don't like it. About your exemple, did you know you can (should?) use route name in the security bundle? instead of |
I'm not convinced about the DX improvement, it doesn't bring much imo, but a new way to do something we can already do easily and quickly, with some PHP code that every newcomer in Symfony can understand. |
@lyrixx yes but I've just copied the docs :) Maybe should we update it. |
Hi, i've just a question on it. Does it is a kind of upgrade of If it is, IMO this controller ( What do you think about that ? |
Not convinced this is that useful. |
Sorry for the misclick :) |
Let's close. |
…le template and redirect controllers (HeahDude) This PR was merged into the 5.1-dev branch. Discussion ---------- [FrameworkBundle][Routing] added Configurators to handle template and redirect controllers | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | let's see | Fixed tickets | partially #24640, #25145 | License | MIT | Doc PR | symfony/symfony-docs#11120 While working on symfony/symfony-docs#11085, I felt bad about the long notations required for simple [redirects](https://symfony.com/doc/current/routing/redirect_in_config.html) and [templates rendering](https://symfony.com/doc/current/templating/render_without_controller.html) template actions, but I love and use those features since always. Then I gave it a try yesterday night and now I realised I missed #24640 and that #25145 has been closed x). So here we go, here's my WIP. WDYT of this implementation? ping @javiereguiluz? I'm going to open the PR in the docs so we can discuss the DX changes there too, and keep focus on the code here. Cheers! EDIT ---- This PR now only update PHP-DSL configurators. ______________ TODO: - [x] gather reviews - ~[x] fix xml schema~ - [x] add some tests - ~[ ] handle xsd auto discovery~ - [x] rebase on top of #30507 - [x] ~add shortcuts for #30514~ Commits ------- de74794 [FrameworkBundle][Routing] added Configurators to handle template and redirect controllers
This PR adds a new built-in controller, similar to
TemplateController
andRedirectController
, allowing to send simple HTTP response without having to write a custom controller:This is especially useful when dealing with the security system, here is a fully working example of a JSON-based login endpoint:
It can also be useful for the following use cases: