diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 93048c408b0d1..7ae73af52d92b 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -72,13 +72,13 @@ public function build(ContainerBuilder $container) public function getContainerExtension() { if (null === $this->extension) { - $class = $this->getContainerExtensionClass(); - if (class_exists($class)) { - $extension = new $class(); + $extension = $this->createContainerExtension(); + if (null !== $extension) { // check naming convention $basename = preg_replace('/Bundle$/', '', $this->getName()); $expectedAlias = Container::underscore($basename); + if ($expectedAlias != $extension->getAlias()) { throw new \LogicException(sprintf( 'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', @@ -208,4 +208,16 @@ protected function getContainerExtensionClass() return $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension'; } + + /** + * Creates the bundle's container extension. + * + * @return ExtensionInterface|null + */ + protected function createContainerExtension() + { + if (class_exists($class = $this->getContainerExtensionClass())) { + return new $class(); + } + } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php index 1a1b30097c4db..d90ccc3f58f67 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php @@ -17,6 +17,16 @@ class BundleTest extends \PHPUnit_Framework_TestCase { + public function testGetContainerExtension() + { + $bundle = new ExtensionPresentBundle(); + + $this->assertInstanceOf( + 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\DependencyInjection\ExtensionPresentExtension', + $bundle->getContainerExtension() + ); + } + public function testRegisterCommands() { $cmd = new FooCommand();
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: