This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle
Nicolas Grekas 45d65cc000 feature #34881 [FrameworkBundle] Allow using the kernel as a registry 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
-------

9c9b99cc65 [FrameworkBundle] Allow using the kernel as a registry of controllers and service factories
2019-12-17 11:12:34 +01:00
..
CacheWarmer Merge branch '4.4' 2019-09-05 14:46:35 +02:00
Command Merge branch '4.4' into 5.0 2019-12-16 11:47:49 +01:00
Console Merge branch '3.4' into 4.3 2019-11-26 04:44:44 +01:00
Controller Merge branch '4.4' into 5.0 2019-12-12 16:09:39 +01:00
DataCollector Remove \Throwable support deprecation layer 2019-11-08 10:00:49 +01:00
DependencyInjection Merge branch '5.0' 2019-12-16 11:48:49 +01:00
EventListener Merge branch '4.4' 2019-09-06 16:33:58 +02:00
HttpCache [FrameworkBundle] Add parameter types from HttpKernel. 2019-08-14 10:52:36 +02:00
Kernel [FrameworkBundle] Allow using the kernel as a registry of controllers and service factories 2019-12-13 14:13:08 +01:00
Resources Merge branch '5.0' 2019-12-16 11:48:49 +01:00
Routing Merge branch '4.4' 2019-10-30 14:25:47 +01:00
Secrets [FrameworkBundle][SodiumVault] Create secrets directory only when needed 2019-12-04 18:30:15 +01:00
Test Merge branch '4.4' 2019-11-05 18:15:52 +01:00
Tests feature #34881 [FrameworkBundle] Allow using the kernel as a registry of controllers and service factories (nicolas-grekas) 2019-12-17 11:12:34 +01:00
Translation Merge branch '4.4' 2019-11-17 11:12:24 +01:00
.gitattributes Add .gitignore to .gitattributes 2019-10-12 01:35:04 +01:00
.gitignore
CHANGELOG.md [FrameworkBundle] Allow using a ContainerConfigurator in MicroKernelTrait::configureContainer() 2019-12-13 14:10:14 +01:00
composer.json [FrameworkBundle] Allow using the kernel as a registry of controllers and service factories 2019-12-13 14:13:08 +01:00
FrameworkBundle.php Merge branch '4.4' 2019-11-12 10:25:44 +01:00
KernelBrowser.php Merge branch '4.4' 2019-09-10 19:00:13 +02:00
LICENSE update year in license files 2019-01-01 14:45:19 +01:00
phpunit.xml.dist Merge branch '2.8' into 3.4 2018-11-11 20:48:54 +01:00
README.md add readme files where missing 2016-03-07 11:36:15 +01:00