Closed
Description
We use a custom DIC based on ContainerBuilder in one of our projects. Our Kernel overwrites the getContainerBaseClass
in order to make sure this DIC is used instead of Container
. As of Symfony 2.8.10 this is broken due to symfony/dependency-injection@e0eeba7#diff-7f4e44bf5b03bfea768fbd537f88c20bR147
Reproduction code:
composer.json
{
"require": {
"symfony/dependency-injection": "2.8.10",
"symfony/http-kernel": "2.8.10",
"symfony/config": "2.8.10"
},
"autoload": {
"classmap": [
"src/"
]
}
}
src/Kernel.php
<?php
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
class Kernel extends BaseKernel
{
public function registerBundles()
{
return [];
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
}
protected function getContainerBaseClass()
{
return ContainerBuilder::class;
}
}
src/issue.php
<?php
require 'vendor/autoload.php';
$kernel = new Kernel('test', true);
$kernel->boot();
Result:
PHP Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\BadMethodCallException' with message 'Setting service "kernel" on a frozen container is not allowed.' in vendor/symfony/dependency-injection/ContainerBuilder.php:396
Stack trace:
#0 vendor/symfony/http-kernel/Kernel.php(520): Symfony\Component\DependencyInjection\ContainerBuilder->set('kernel', Object(Kernel))
#1 vendor/symfony/http-kernel/Kernel.php(133): Symfony\Component\HttpKernel\Kernel->initializeContainer()
#2 src/issue.php(6): Symfony\Component\HttpKernel\Kernel->boot()
#3 {main}
thrown in vendor/symfony/dependency-injection/ContainerBuilder.php on line 396
Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\BadMethodCallException' with message 'Setting service "kernel" on a frozen container is not allowed.' in vendor/symfony/dependency-injection/ContainerBuilder.php:396
Stack trace:
#0 vendor/symfony/http-kernel/Kernel.php(520): Symfony\Component\DependencyInjection\ContainerBuilder->set('kernel', Object(Kernel))
#1 vendor/symfony/http-kernel/Kernel.php(133): Symfony\Component\HttpKernel\Kernel->initializeContainer()
#2 src/issue.php(6): Symfony\Component\HttpKernel\Kernel->boot()
#3 {main}
thrown in vendor/symfony/dependency-injection/ContainerBuilder.php on line 396
The solution could be to extend from Container
instead of ContainerBuilder
, but at this time I don't yet know it that has any other consequences.