Skip to content

Commit 6c50013

Browse files
committed
Allowed extensions to inline compiler passes
1 parent a630d87 commit 6c50013

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
7+
/**
8+
* A pass to automatically process extensions if they implement
9+
* CompilerPassInterface.
10+
*
11+
* @author Wouter J <wouter@wouterj.nl>
12+
*/
13+
class ExtensionCompilerPass implements CompilerPassInterface
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function process(ContainerBuilder $container)
19+
{
20+
foreach ($container->getExtensions() as $extension) {
21+
if (!$extension instanceof CompilerPassInterface) {
22+
continue;
23+
}
24+
25+
$extension->process($container);
26+
}
27+
}
28+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function __construct()
4545
$this->mergePass = new MergeExtensionConfigurationPass();
4646

4747
$this->optimizationPasses = array(
48+
new ExtensionCompilerPass(),
4849
new ResolveDefinitionTemplatesPass(),
4950
new DecoratorServicePass(),
5051
new ResolveParameterPlaceHoldersPass(),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass;
6+
7+
/**
8+
* @author Wouter J <wouter@wouterj.nl>
9+
*/
10+
class ExtensionCompilerPassTest extends \PHPUnit_Framework_TestCase
11+
{
12+
private $container;
13+
private $pass;
14+
15+
public function setUp()
16+
{
17+
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
18+
$this->pass = new ExtensionCompilerPass();
19+
}
20+
21+
public function testProcess()
22+
{
23+
$extension1 = $this->createExtensionMock(true);
24+
$extension1->expects($this->once())->method('process');
25+
$extension2 = $this->createExtensionMock(false);
26+
$extension3 = $this->createExtensionMock(false);
27+
$extension4 = $this->createExtensionMock(true);
28+
$extension4->expects($this->once())->method('process');
29+
30+
$this->container->expects($this->any())
31+
->method('getExtensions')
32+
->will($this->returnValue(array($extension1, $extension2, $extension3, $extension4)))
33+
;
34+
35+
$this->pass->process($this->container);
36+
}
37+
38+
private function createExtensionMock($hasInlineCompile)
39+
{
40+
return $this->getMock('Symfony\Component\DependencyInjection\\'.(
41+
$hasInlineCompile
42+
? 'Compiler\CompilerPassInterface'
43+
: 'Extension\ExtensionInterface'
44+
));
45+
}
46+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy