-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Allow using the kernel as a registry of controllers and service factories #34881
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
2cb3d9a
to
86da1af
Compare
62fec54
to
cc9f9f2
Compare
PR is ready, now with tests. |
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.
Nice :), LGTM!
e5873f6
to
11bc128
Compare
7695648
to
bade028
Compare
… and service factories
bade028
to
9c9b99c
Compare
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 like this = +1
Just make sure you make fabbot happy ;)
… of controllers and service factories (nicolas-grekas) This PR was merged into the 5.1-dev branch. Discussion ---------- [FrameworkBundle] Allow using the kernel as a registry of controllers and service factories | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #28992, fix #29997 | License | MIT | Doc PR | - This PR builds on #34873 and #34872 and allows using the `Kernel` as a registry of autowired controllers and service factories. The `ContainerConfigurator` passed to `configureContainer()` defaults to declaring autowired and autoconfigured services. TL;DR: Silex is back but in a much more powerful way \o/ Here is a Kernel that just works and displays `Hello App\Foo` on the `/` route: ```php class Kernel extends BaseKernel { use MicroKernelTrait; protected function configureContainer(ContainerConfigurator $container): void { $container->services() ->load('App\\', '../src') ->set(Foo::class) ->factory([$this, 'createFoo']); } public function createFoo(Bar $bar) { return new Foo($bar); } protected function configureRoutes(RoutingConfigurator $routes): void { $routes->add('home', '/')->controller([$this, 'helloAction']); } public function helloAction(Foo $foo) { return new Response('Hello '.get_class($foo)); } } ``` Commits ------- 9c9b99c [FrameworkBundle] Allow using the kernel as a registry of controllers and service factories
That sounds really interesting! Since you closed #28992 is it possible to use anonymous functions to declare services? |
Anonymous functions won't happen, I've explained why in #28992 (code relocation is full of edge cases we don't want to deal with). But this PR provides an alternative to using closures, by using methods on the Kernel. Let's see how far this goes :) |
Oh OK, thanks for the clarification. Since #28992 was specifically about closures, and it was marked as "fixed" by this PR, this was confusing. |
Thanks for asking, it deserved the clarification :) |
This PR builds on #34873 and #34872 and allows using the
Kernel
as a registry of autowired controllers and service factories. TheContainerConfigurator
passed toconfigureContainer()
defaults to declaring autowired and autoconfigured services.TL;DR: Silex is back but in a much more powerful way \o/
Here is a Kernel that just works and displays
Hello App\Foo
on the/
route: