Skip to content

Commit 7707c0f

Browse files
committed
[Kernel] Fix bundle inheritance
1 parent 839782b commit 7707c0f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ public function getLogDir()
369369
*
370370
* @throws \LogicException if two bundles share a common name
371371
* @throws \LogicException if a bundle tries to extend a non-registered bundle
372+
* @throws \LogicException if a bundle tries to extend itself
372373
* @throws \LogicException if two bundles extend the same ancestor
373374
*/
374375
protected function initializeBundles()
@@ -389,6 +390,9 @@ protected function initializeBundles()
389390
if (isset($directChildren[$parentName])) {
390391
throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
391392
}
393+
if ($parentName == $name) {
394+
throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
395+
}
392396
$directChildren[$parentName] = $name;
393397
} else {
394398
$topMostBundles[$name] = $bundle;

tests/Symfony/Tests/Component/HttpKernel/KernelTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,22 @@ public function testInitializeBundleThrowsExceptionWhenRegisteringTwoBundlesWith
620620
$kernel->initializeBundles();
621621
}
622622

623+
/**
624+
* @expectedException \LogicException
625+
*/
626+
public function testInitializeBundleThrowsExceptionWhenABundleExtendsItself()
627+
{
628+
$circularRef = $this->getBundle(null, 'CircularRefBundle', 'CircularRefBundle');
629+
630+
$kernel = $this->getKernel();
631+
$kernel
632+
->expects($this->once())
633+
->method('registerBundles')
634+
->will($this->returnValue(array($circularRef)))
635+
;
636+
$kernel->initializeBundles();
637+
}
638+
623639
protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null)
624640
{
625641
$bundle = $this

0 commit comments

Comments
 (0)