Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e1a0ea

Browse files
[HttpKernel][DI] Enable Kernel to implement CompilerPassInterface
1 parent 55a7691 commit 2e1a0ea

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ExtensionCompilerPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ public function process(ContainerBuilder $container)
3333

3434
$extension->process($container);
3535
}
36+
37+
if ($container->getKernelPass()) {
38+
$container->getKernelPass()->process($container);
39+
}
3640
}
3741
}

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
121121

122122
private $autoconfiguredInstanceof = array();
123123

124+
private $kernelPass;
125+
124126
public function __construct(ParameterBagInterface $parameterBag = null)
125127
{
126128
parent::__construct($parameterBag);
@@ -701,6 +703,16 @@ public function prependExtensionConfig($name, array $config)
701703
array_unshift($this->extensionConfigs[$name], $config);
702704
}
703705

706+
public function setKernelPass(CompilerPassInterface $kernelPass)
707+
{
708+
$this->kernelPass = $kernelPass;
709+
}
710+
711+
public function getKernelPass()
712+
{
713+
return $this->kernelPass;
714+
}
715+
704716
/**
705717
* Compiles the container.
706718
*

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
1515
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
16+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1617
use Symfony\Component\DependencyInjection\ContainerInterface;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@@ -767,6 +768,9 @@ protected function getContainerBuilder()
767768
$container = new ContainerBuilder();
768769
$container->getParameterBag()->add($this->getKernelParameters());
769770

771+
if ($this instanceof CompilerPassInterface) {
772+
$container->setKernelPass($this);
773+
}
770774
if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator')) {
771775
$container->setProxyInstantiator(new RuntimeInstantiator());
772776
}

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\Loader\LoaderInterface;
16+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\Filesystem\Filesystem;
1819
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
@@ -831,6 +832,14 @@ public function testKernelReset()
831832
$this->assertFileNotExists($containerFile);
832833
}
833834

835+
public function testKernelPass()
836+
{
837+
$kernel = new PassKernel();
838+
$kernel->boot();
839+
840+
$this->assertTrue($kernel->getContainer()->getParameter('test.processed'));
841+
}
842+
834843
/**
835844
* Returns a mock for the BundleInterface.
836845
*
@@ -967,3 +976,17 @@ protected function build(ContainerBuilder $container)
967976
}
968977
}
969978
}
979+
980+
class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface
981+
{
982+
public function __construct(\Closure $buildContainer = null)
983+
{
984+
parent::__construct();
985+
Kernel::__construct('pass', true);
986+
}
987+
988+
public function process(ContainerBuilder $container)
989+
{
990+
$container->setParameter('test.processed', true);
991+
}
992+
}

0 commit comments

Comments
 (0)