Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Symfony\Component\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* A pass to automatically process extensions if they implement
* CompilerPassInterface.
*
* @author Wouter J <wouter@wouterj.nl>
*/
class ExtensionCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
foreach ($container->getExtensions() as $extension) {
if (!$extension instanceof CompilerPassInterface) {
continue;
}

$extension->process($container);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct()
$this->mergePass = new MergeExtensionConfigurationPass();

$this->optimizationPasses = array(
new ExtensionCompilerPass(),
new ResolveDefinitionTemplatesPass(),
new DecoratorServicePass(),
new ResolveParameterPlaceHoldersPass(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Symfony\Component\DependencyInjection\Tests\Compiler;

use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass;

/**
* @author Wouter J <wouter@wouterj.nl>
*/
class ExtensionCompilerPassTest extends \PHPUnit_Framework_TestCase
{
private $container;
private $pass;

public function setUp()
{
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
$this->pass = new ExtensionCompilerPass();
}

public function testProcess()
{
$extension1 = $this->createExtensionMock(true);
$extension1->expects($this->once())->method('process');
$extension2 = $this->createExtensionMock(false);
$extension3 = $this->createExtensionMock(false);
$extension4 = $this->createExtensionMock(true);
$extension4->expects($this->once())->method('process');

$this->container->expects($this->any())
->method('getExtensions')
->will($this->returnValue(array($extension1, $extension2, $extension3, $extension4)))
;

$this->pass->process($this->container);
}

private function createExtensionMock($hasInlineCompile)
{
return $this->getMock('Symfony\Component\DependencyInjection\\'.(
$hasInlineCompile
? 'Compiler\CompilerPassInterface'
: 'Extension\ExtensionInterface'
));
}
}