8000 Auto-register kernel as an extension · symfony/symfony@9c34980 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c34980

Browse files
committed
Auto-register kernel as an extension
1 parent 772547e commit 9c34980

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* content of request parameter `_password` is now also hidden
1212
in the request profiler raw content section
1313
* Allowed adding attributes on controller arguments that will be passed to argument resolvers.
14+
* kernels implementing the `ExtensionInterface` will now be auto-registered to the container
1415

1516
5.1.0
1617
-----

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\DependencyInjection\ContainerInterface;
2424
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
2525
use Symfony\Component\DependencyInjection\Dumper\Preloader;
26+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2627
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
2728
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
2829
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
@@ -688,6 +689,9 @@ protected function getContainerBuilder()
688689
$container = new ContainerBuilder();
689690
$container->getParameterBag()->add($this->getKernelParameters());
690691

692+
if ($this instanceof ExtensionInterface) {
693+
$container->registerExtension($this);
694+
}
691695
if ($this instanceof CompilerPassInterface) {
692696
$container->addCompilerPass($this, PassConfig::TYPE_BEFORE_OPTIMIZATION, -10000);
693697
}

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\ContainerInterface;
19+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
1920
use Symfony\Component\Filesystem\Filesystem;
2021
use Symfony\Component\HttpFoundation\Request;
2122
use Symfony\Component\HttpFoundation\Response;
@@ -475,6 +476,34 @@ public function testKernelReset()
475476
$this->assertFileExists(\dirname($containerFile).'.legacy');
476477
}
477478

479+
public function testKernelExtension()
480+
{
481+
$kernel = new class() extends CustomProjectDirKernel implements ExtensionInterface {
482+
public function load(array $configs, ContainerBuilder $container)
483+
{
484+
$container->setParameter('test.extension-registered', true);
485+
}
486+
487+
public function getNamespace()
488+
{
489+
return '';
490+
}
491+
492+
public function getXsdValidationBasePath()
493+
{
494+
return false;
495+
}
496+
497+
public function getAlias()
498+
{
499+
return 'test-extension';
500+
}
501+
};
502+
$kernel->boot();
503+
504+
$this->assertTrue($kernel->getContainer()->getParameter('test.extension-registered'));
505+
}
506+
478507
public function testKernelPass()
479508
{
480509
$kernel = new PassKernel();

0 commit comments

Comments
 (0)
0