8000 feature #38243 [HttpKernel] Auto-register kernel as an extension (Hyp… · symfony/http-kernel@e3b70cb · GitHub
[go: up one dir, main page]

Skip to content

Commit e3b70cb

Browse files
committed
feature #38243 [HttpKernel] Auto-register kernel as an extension (HypeMC)
This PR was merged into the 5.2-dev branch. Discussion ---------- [HttpKernel] Auto-register kernel as an extension | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Symfony already supports having the kernel as an extension. This is evident by the fact that the [`config:dump-reference` and `debug:config`](symfony/symfony#36186) commands check whether the kernel implements the `ExtensionInterface`. Nonetheless, it's still required to register the kernel manually as an extension. With this PR the kernel will be automatically registered as an extension if it implements the `ExtensionInterface`. This is the same logic as when the kernel implements the `CompilerPassInterface`. Commits ------- 9c34980869 Auto-register kernel as an extension
2 parents 793157b + b51d6d3 commit e3b70cb

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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
-----

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
}

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