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

Skip to content

Commit 6973a1a

Browse files
[HttpKernel][DI] Enable Kernel to implement CompilerPassInterface
1 parent aad62c4 commit 6973a1a

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

UPGRADE-4.0.md

+2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ DependencyInjection
184184

185185
* Top-level anonymous services in XML are no longer supported.
186186

187+
* The `ExtensionCompilerPass` has been moved to before-optimization passes with priority -1000.
188+
187189
EventDispatcher
188190
---------------
189191

src/Symfony/Component/DependencyInjection/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
3.4.0
55
-----
66

7+
* moved the `ExtensionCompilerPass` to before-optimization passes with priority -1000
78
* deprecated "public-by-default" definitions and aliases, the new default will be "private" in 4.0
89
* added `EnvVarProcessorInterface` and corresponding "container.env_var_processor" tag for processing env vars
910
* added support for ignore-on-uninitialized references

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public function __construct()
4545
new ResolveInstanceofConditionalsPass(),
4646
new RegisterEnvVarProcessorsPass(),
4747
),
48+
-1000 => array(new ExtensionCompilerPass()),
4849
);
4950

5051
$this->optimizationPasses = array(array(
51-
new ExtensionCompilerPass(),
5252
new ResolveChildDefinitionsPass(),
5353
new ServiceLocatorTagPass(),
5454
new DecoratorServicePass(),

src/Symfony/Component/HttpKernel/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
3.4.0
55
-----
66

7+
* made kernels implementing `CompilerPassInterface` able to process the container
78
* deprecated bundle inheritance
89
* added `RebootableInterface` and implemented it in `Kernel`
910
* deprecated commands auto registration

src/Symfony/Component/HttpKernel/Kernel.php

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
1515
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
16+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
1618
use Symfony\Component\DependencyInjection\ContainerInterface;
1719
use Symfony\Component\DependencyInjection\ContainerBuilder;
1820
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@@ -767,6 +769,9 @@ protected function getContainerBuilder()
767769
$container = new ContainerBuilder();
768770
$container->getParameterBag()->add($this->getKernelParameters());
769771

772+
if ($this instanceof CompilerPassInterface) {
773+
$container->addCompilerPass($this, PassConfig::TYPE_BEFORE_OPTIMIZATION, -10000);
774+
}
770775
if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator')) {
771776
$container->setProxyInstantiator(new RuntimeInstantiator());
772777
}

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

+23
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)