-
-
Notifications
You must be signed in to change notification settings - Fork 422
Extending from AbstractController in controller skeletons #20
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
This is a tricky one. I agree with the best practice, but I’m not sure if we should yet push people to AbstractController. But, if you’re generating a controller, then it’s new code. So maybe? We’ve decided on the docs to keep showing Controller for at least one version more. |
I'm personally 👍: now that services are private by default, making them public does require typing configuration. |
For Also, I would rename the |
Also, |
I don't agree with this: the helpers provided by the base class are not "coupling" anymore, thanks to the dedicated service locator that is injected. Extending the AbstractController allows better self-discovery of the features provided by Symfony. |
I don't agree with this: this actively prevents putting more actions into one controller. I understand that one-controller-class-per-route is a common practice, yet I don't think it should be the default one. |
It's not the case. You can have both an
I definitely prefer the one-controller-class-per-route approach. It should at least be used if the controller contains 1 action (as in the generated one). |
You need |
902855c
to
f5aa030
Compare
Anyway, it would be nice to let the user configuring the strategy he wants. What about a config flag to choose globally between |
What about a new controller skeleton for ADR pattern?
|
@yceruto same idea (but strictly speaking it's not the ADR pattern so it should no be called ADR-something - there is no Responder in my proposal). |
framework-bundle is a mandatory requirement of Flex anyway and extending this class is not what I would actually call coupling in this case, because the base class provides only simple helpers, vs a full chain reaction of dependencies when Controller is needed (the container)
let's keep things simple really |
Yes, but it doesn't mean that the "controller" (action?) class has to be coupled with it too.
It means that you need this specific lib and its dependencies to execute it. Anyway this PR is a step in the good direction. Let's merge it, we can discuss this elsewhere. |
that's exactly where I stop agreeing :) the base class has no dependencies at all that you don't want/need. |
It depends, we reuse some API Platform controllers with Laravel (yes, it works). It will not be possible to do it without requiring That being said, I agree that |
That won't work fine. you cannot use routing annotations without FrameworkExtraBundle anyway (we plan to change this for a future 4.x release) |
what do you have in mind? we made the routing annotation work with services, which was missing before. Is there anything else left? |
The Routing component only provides an abstract AnnotationClassLoader which is a partial implementation. The concrete implementation still lives in the bundle. |
@nicolas-grekas here it is: symfony/symfony#25103 |
f5aa030
to
b1701e2
Compare
Thank you @yceruto. |
… (yceruto) This PR was merged into the 1.0-dev branch. Discussion ---------- Extending from AbstractController in controller skeletons > https://symfony.com/doc/master/best_practices/controllers.html#controllers > [Best Practice] Make your controller extend the `AbstractController` base controller provided by Symfony and use annotations to configure routing, caching and security whenever possible. > https://symfony.com/doc/master/best_practices/controllers.html#fetching-services > [Best Practice] Don't use `$this->get()` or `$this->container->get()` to fetch services from the container. Instead, use dependency injection. Commits ------- b1701e2 Extending from AbstractController in controller skeletons