Auto-register kernel as an extension
This commit is contained in:
parent
772547ec02
commit
9c34980869
@ -11,6 +11,7 @@ CHANGELOG
|
|||||||
* content of request parameter `_password` is now also hidden
|
* content of request parameter `_password` is now also hidden
|
||||||
in the request profiler raw content section
|
in the request profiler raw content section
|
||||||
* Allowed adding attributes on controller arguments that will be passed to argument resolvers.
|
* Allowed adding attributes on controller arguments that will be passed to argument resolvers.
|
||||||
|
* kernels implementing the `ExtensionInterface` will now be auto-registered to the container
|
||||||
|
|
||||||
5.1.0
|
5.1.0
|
||||||
-----
|
-----
|
||||||
|
@ -23,6 +23,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
||||||
use Symfony\Component\DependencyInjection\Dumper\Preloader;
|
use Symfony\Component\DependencyInjection\Dumper\Preloader;
|
||||||
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||||
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
||||||
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
|
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
|
||||||
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
|
||||||
@ -688,6 +689,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
|||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
$container->getParameterBag()->add($this->getKernelParameters());
|
$container->getParameterBag()->add($this->getKernelParameters());
|
||||||
|
|
||||||
|
if ($this instanceof ExtensionInterface) {
|
||||||
|
$container->registerExtension($this);
|
||||||
|
}
|
||||||
if ($this instanceof CompilerPassInterface) {
|
if ($this instanceof CompilerPassInterface) {
|
||||||
$container->addCompilerPass($this, PassConfig::TYPE_BEFORE_OPTIMIZATION, -10000);
|
$container->addCompilerPass($this, PassConfig::TYPE_BEFORE_OPTIMIZATION, -10000);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Config\Loader\LoaderInterface;
|
|||||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@ -475,6 +476,34 @@ EOF;
|
|||||||
$this->assertFileExists(\dirname($containerFile).'.legacy');
|
$this->assertFileExists(\dirname($containerFile).'.legacy');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testKernelExtension()
|
||||||
|
{
|
||||||
|
$kernel = new class() extends CustomProjectDirKernel implements ExtensionInterface {
|
||||||
|
public function load(array $configs, ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
$container->setParameter('test.extension-registered', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNamespace()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getXsdValidationBasePath()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAlias()
|
||||||
|
{
|
||||||
|
return 'test-extension';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$kernel->boot();
|
||||||
|
|
||||||
|
$this->assertTrue($kernel->getContainer()->getParameter('test.extension-registered'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testKernelPass()
|
public function testKernelPass()
|
||||||
{
|
{
|
||||||
$kernel = new PassKernel();
|
$kernel = new PassKernel();
|
||||||
|
Reference in New Issue
Block a user