Skip to content

[HttpKernel][DI] Enable Kernel to implement CompilerPassInterface #24257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
3.4.0
-----

* moved the `ExtensionCompilerPass` to before-optimization passes with priority -1000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be worth adding this to the upgrade file too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
23 changes: 23 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}