Permalink
Browse files

feature #24257 [HttpKernel][DI] Enable Kernel to implement CompilerPa…

…ssInterface (nicolas-grekas)

This PR was squashed before being merged into the 3.4 branch (closes #24257).

Discussion
----------

[HttpKernel][DI] Enable Kernel to implement CompilerPassInterface

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

In the same spirit as #13761 that allowed DI exts to be also compiler passes, and as #23812 that allowed the kernel to listen to events, in our new bundle-less world, should we allow the kernel to register itself as a compiler pass? That would make some scenario possible (like having a `TestKernel` that turns some services public.)

Commits
-------

6973a1a [HttpKernel][DI] Enable Kernel to implement CompilerPassInterface
  • Loading branch information...
nicolas-grekas committed Sep 20, 2017
2 parents 2f86474 + 6973a1a commit 701d41cc33924cbdb9fb710ce63524a86c2de3c6
View
@@ -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 @@ public function __construct()
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 @@
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 @@ protected function getContainerBuilder()
$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 @@
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 @@ public function testKernelReset()
$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 @@ protected function build(ContainerBuilder $container)
}
}
}
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);
}
}

0 comments on commit 701d41c

Please sign in to comment.