Skip to content

Commit

Permalink
[HttpKernel] added back Bundle::getName() as it is quite useful
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 21, 2011
1 parent 6d1e91a commit e6f1248
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
19 changes: 18 additions & 1 deletion src/Symfony/Component/HttpKernel/Bundle/Bundle.php
Expand Up @@ -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;

Expand All @@ -25,6 +24,8 @@
*/
abstract class Bundle extends ContainerAware implements BundleInterface
{
protected $name;

/**
* Boots the Bundle.
*/
Expand All @@ -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.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
Expand Up @@ -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.
*
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -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();
Expand Down
13 changes: 12 additions & 1 deletion tests/Symfony/Tests/Component/HttpKernel/KernelTest.php
Expand Up @@ -145,6 +145,7 @@ public function testInitializeBundlesSupportInheritanceCascade()
->method('registerBundles')
->will($this->returnValue(array($parent, $grandparent, $child)))
;

$kernel->initializeBundles();

$map = $kernel->getBundleMap();
Expand Down Expand Up @@ -189,14 +190,24 @@ 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);
}

$bundle = $bundle->getMock();

$bundle
->expects($this->any())
->method('getName')
->will($this->returnValue(get_class($bundle)))
;

if (null !== $dir) {
$bundle
->expects($this->any())
Expand Down

0 comments on commit e6f1248

Please sign in to comment.