Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote branch 'kriswallsmith/dic/auto-ext-load'
* kriswallsmith/dic/auto-ext-load: [HttpKernel] added an subclass merge extension configuration compiler pass to ensure each bundle's "main" extension is loaded [DependencyInjection] extensions should only load if called during configuration
- Loading branch information
Showing
12 changed files
with
251 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony framework. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass as BaseMergeExtensionConfigurationPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* Handles automatically loading each bundle's default extension. | ||
* | ||
* @author Kris Wallsmith <kris.wallsmith@symfony-project.com> | ||
*/ | ||
class MergeExtensionConfigurationPass extends BaseMergeExtensionConfigurationPass | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
foreach ($container->getParameter('kernel.bundles') as $bundleName => $bundleClass) { | ||
$bundleRefl = new \ReflectionClass($bundleClass); | ||
$extClass = $bundleRefl->getNamespaceName().'\\DependencyInjection\\'.substr($bundleName, 0, -6).'Extension'; | ||
|
||
if (class_exists($extClass)) { | ||
$ext = new $extClass(); | ||
$alias = $ext->getAlias(); | ||
|
||
// ensure all "main" extensions are loaded | ||
if (!count($container->getExtensionConfig($alias))) { | ||
$container->loadFromExtension($alias, array()); | ||
} | ||
} | ||
} | ||
|
||
parent::process($container); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ny/Tests/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\HttpKernel; | ||
|
||
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; | ||
|
||
class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testAutoloadMainExtension() | ||
{ | ||
$bundles = array( | ||
'ExtensionAbsentBundle' => 'Symfony\\Tests\\Component\\HttpKernel\\Fixtures\\ExtensionAbsentBundle\\ExtensionAbsentBundle', | ||
'ExtensionLoadedBundle' => 'Symfony\\Tests\\Component\\HttpKernel\\Fixtures\\ExtensionLoadedBundle\\ExtensionLoadedBundle', | ||
'ExtensionPresentBundle' => 'Symfony\\Tests\\Component\\HttpKernel\\Fixtures\\ExtensionPresentBundle\\ExtensionPresentBundle', | ||
); | ||
|
||
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); | ||
$params = $this->getMock('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBag'); | ||
|
||
$container->expects($this->once()) | ||
->method('getParameter') | ||
->with('kernel.bundles') | ||
->will($this->returnValue($bundles)); | ||
$container->expects($this->exactly(2)) | ||
->method('getExtensionConfig') | ||
->will($this->returnCallback(function($name) { | ||
switch ($name) { | ||
case 'extension_present': | ||
return array(); | ||
case 'extension_loaded': | ||
return array(array()); | ||
} | ||
})); | ||
$container->expects($this->once()) | ||
->method('loadFromExtension') | ||
->with('extension_present', array()); | ||
|
||
$container->expects($this->any()) | ||
->method('getParameterBag') | ||
->will($this->returnValue($params)); | ||
$params->expects($this->any()) | ||
->method('all') | ||
->will($this->returnValue(array())); | ||
$container->expects($this->any()) | ||
->method('getDefinitions') | ||
->will($this->returnValue(array())); | ||
$container->expects($this->any()) | ||
->method('getAliases') | ||
->will($this->returnValue(array())); | ||
$container->expects($this->any()) | ||
->method('getExtensions') | ||
->will($this->returnValue(array())); | ||
|
||
$configPass = new MergeExtensionConfigurationPass(); | ||
$configPass->process($container); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...mfony/Tests/Component/HttpKernel/Fixtures/ExtensionAbsentBundle/ExtensionAbsentBundle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\HttpKernel\Fixtures\ExtensionAbsentBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class ExtensionAbsentBundle extends Bundle | ||
{ | ||
} |
22 changes: 22 additions & 0 deletions
22
...ttpKernel/Fixtures/ExtensionLoadedBundle/DependencyInjection/ExtensionLoadedExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\HttpKernel\Fixtures\ExtensionLoadedBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
class ExtensionLoadedExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...mfony/Tests/Component/HttpKernel/Fixtures/ExtensionLoadedBundle/ExtensionLoadedBundle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\HttpKernel\Fixtures\ExtensionLoadedBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class ExtensionLoadedBundle extends Bundle | ||
{ | ||
} |
22 changes: 22 additions & 0 deletions
22
...pKernel/Fixtures/ExtensionPresentBundle/DependencyInjection/ExtensionPresentExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\HttpKernel\Fixtures\ExtensionPresentBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
class ExtensionPresentExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ony/Tests/Component/HttpKernel/Fixtures/ExtensionPresentBundle/ExtensionPresentBundle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\HttpKernel\Fixtures\ExtensionPresentBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class ExtensionPresentBundle extends Bundle | ||
{ | ||
} |