[HttpKernel][DI] Enable Kernel to implement CompilerPassInterface
This commit is contained in:
parent
aad62c427c
commit
6973a1ae3b
@ -184,6 +184,8 @@ DependencyInjection
|
||||
|
||||
* Top-level anonymous services in XML are no longer supported.
|
||||
|
||||
* The `ExtensionCompilerPass` has been moved to before-optimization passes with priority -1000.
|
||||
|
||||
EventDispatcher
|
||||
---------------
|
||||
|
||||
|
@ -4,6 +4,7 @@ CHANGELOG
|
||||
3.4.0
|
||||
-----
|
||||
|
||||
* moved the `ExtensionCompilerPass` to before-optimization passes with priority -1000
|
||||
* deprecated "public-by-default" definitions and aliases, the new default will be "private" in 4.0
|
||||
* added `EnvVarProcessorInterface` and corresponding "container.env_var_processor" tag for processing env vars
|
||||
* added support for ignore-on-uninitialized references
|
||||
|
@ -45,10 +45,10 @@ class PassConfig
|
||||
new ResolveInstanceofConditionalsPass(),
|
||||
new RegisterEnvVarProcessorsPass(),
|
||||
),
|
||||
-1000 => array(new ExtensionCompilerPass()),
|
||||
);
|
||||
|
||||
$this->optimizationPasses = array(array(
|
||||
new ExtensionCompilerPass(),
|
||||
new ResolveChildDefinitionsPass(),
|
||||
new ServiceLocatorTagPass(),
|
||||
new DecoratorServicePass(),
|
||||
|
@ -4,6 +4,7 @@ CHANGELOG
|
||||
3.4.0
|
||||
-----
|
||||
|
||||
* made kernels implementing `CompilerPassInterface` able to process the container
|
||||
* deprecated bundle inheritance
|
||||
* added `RebootableInterface` and implemented it in `Kernel`
|
||||
* deprecated commands auto registration
|
||||
|
@ -13,6 +13,8 @@ namespace Symfony\Component\HttpKernel;
|
||||
|
||||
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
|
||||
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
||||
@ -767,6 +769,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
$container = new ContainerBuilder();
|
||||
$container->getParameterBag()->add($this->getKernelParameters());
|
||||
|
||||
if ($this instanceof CompilerPassInterface) {
|
||||
$container->addCompilerPass($this, PassConfig::TYPE_BEFORE_OPTIMIZATION, -10000);
|
||||
}
|
||||
if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator')) {
|
||||
$container->setProxyInstantiator(new RuntimeInstantiator());
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
@ -831,6 +832,14 @@ EOF;
|
||||
$this->assertFileNotExists($containerFile);
|
||||
}
|
||||
|
||||
public function testKernelPass()
|
||||
{
|
||||
$kernel = new PassKernel();
|
||||
$kernel->boot();
|
||||
|
||||
$this->assertTrue($kernel->getContainer()->getParameter('test.processed'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mock for the BundleInterface.
|
||||
*
|
||||
@ -967,3 +976,17 @@ class CustomProjectDirKernel extends Kernel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface
|
||||
{
|
||||
public function __construct(\Closure $buildContainer = null)
|
||||
{
|
||||
parent::__construct();
|
||||
Kernel::__construct('pass', true);
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$container->setParameter('test.processed', true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user