diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index ec820625798a..ef11fb260c72 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -13,7 +13,6 @@ use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Console\Application; use Symfony\Component\Finder\Finder; @@ -25,6 +24,8 @@ */ abstract class Bundle extends ContainerAware implements BundleInterface { + protected $name; + /** * Boots the Bundle. */ @@ -49,6 +50,22 @@ public function getParent() return null; } + /** + * Returns the bundle name (the class short name). + * + * @return string The Bundle name + */ + final public function getName() + { + if (null !== $this->name) { + return $this->name; + } + + $pos = strrpos(get_class($this), '\\'); + + return $this->name = substr(get_class($this), $pos ? $pos + 1 : 0); + } + /** * Finds and registers Dependency Injection Container extensions. * diff --git a/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php b/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php index f5146eb7004f..1e4f2a7487ea 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php +++ b/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php @@ -35,6 +35,13 @@ function shutdown(); */ function getParent(); + /** + * Returns the bundle name (the class short name). + * + * @return string The Bundle name + */ + function getName(); + /** * Gets the Bundle namespace. * diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index ed7dbb901ecf..27583208f134 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -410,8 +410,7 @@ protected function initializeBundles() // init bundles $this->bundles = array(); foreach ($this->registerBundles() as $bundle) { - $parts = explode('\\', get_class($bundle)); - $name = $parts[count($parts) - 1]; + $name = $bundle->getName(); $this->bundles[$name] = $bundle; if (!isset($this->bundleMap[$name])) { $this->bundleMap[$name] = array(); diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index 531d0bab9257..e66b8aee9c33 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -145,6 +145,7 @@ public function testInitializeBundlesSupportInheritanceCascade() ->method('registerBundles') ->will($this->returnValue(array($parent, $grandparent, $child))) ; + $kernel->initializeBundles(); $map = $kernel->getBundleMap(); @@ -189,7 +190,11 @@ public function testInitializeBundlesThrowsExceptionWhenABundleIsDirectlyExtende protected function getBundle($dir = null, $parent = null, $className = null) { - $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface'); + $bundle = $this + ->getMockBuilder('Symfony\Tests\Component\HttpKernel\KernelForTest') + ->setMethods(array('getPath', 'getParent', 'getName')) + ->disableOriginalConstructor() + ; if ($className) { $bundle->setMockClassName($className); @@ -197,6 +202,12 @@ protected function getBundle($dir = null, $parent = null, $className = null) $bundle = $bundle->getMock(); + $bundle + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(get_class($bundle))) + ; + if (null !== $dir) { $bundle ->expects($this->any())