Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 89893c1

Browse filesBrowse files
committed
[HttpKernel] deprecated bundle inheritance
1 parent ee9f4c3 commit 89893c1
Copy full SHA for 89893c1

File tree

Expand file treeCollapse file tree

8 files changed

+53
-4
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+53
-4
lines changed

‎UPGRADE-3.4.md

Copy file name to clipboardExpand all lines: UPGRADE-3.4.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ FrameworkBundle
173173
HttpKernel
174174
----------
175175

176+
* Bundle inheritance has been deprecated.
177+
176178
* Relying on convention-based commands discovery has been deprecated and
177179
won't be supported in 4.0. Use PSR-4 based service discovery instead.
178180

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,8 @@ HttpFoundation
493493
HttpKernel
494494
----------
495495

496+
* Bundle inheritance has been removed.
497+
496498
* Relying on convention-based commands discovery is not supported anymore.
497499
Use PSR-4 based service discovery instead.
498500

‎src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function parse($controller)
5858

5959
try {
6060
// this throws an exception if there is no such bundle
61-
$allBundles = $this->kernel->getBundle($bundle, false);
61+
$allBundles = $this->kernel->getBundle($bundle, false, true);
6262
} catch (\InvalidArgumentException $e) {
6363
$message = sprintf(
6464
'The "%s" (from the _controller value "%s") does not exist or is not enabled in your kernel!',
@@ -141,7 +141,7 @@ private function findAlternative($nonExistentBundleName)
141141
}
142142

143143
$lev = levenshtein($nonExistentBundleName, $bundleName);
144-
if ($lev <= strlen($nonExistentBundleName) / 3 && ($alternative === null || $lev < $shortest)) {
144+
if ($lev <= strlen($nonExistentBundleName) / 3 && (null === $alternative || $lev < $shortest)) {
145145
$alternative = $bundleName;
146146
$shortest = $lev;
147147
}

‎src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function getContainerExtension();
5656
* bundle.
5757
*
5858
* @return string The Bundle name it overrides or null if no parent
59+
*
60+
* @deprecated This method is deprecated as of 3.4 and will be removed in 4.0.
5961
*/
6062
public function getParent();
6163

‎src/Symfony/Component/HttpKernel/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
3.4.0
55
-----
66

7+
* deprecated bundle inheritance
78
* added `RebootableInterface` and implemented it in `Kernel`
89
* deprecated commands auto registration
910
* added `AddCacheClearerPass`

‎src/Symfony/Component/HttpKernel/Kernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Kernel.php
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,17 @@ public function getBundles()
204204
/**
205205
* {@inheritdoc}
206206
*/
207-
public function getBundle($name, $first = true)
207+
public function getBundle($name, $first = true/*, $noDeprecation = false */)
208208
{
209+
$noDeprecation = false;
210+
if (func_num_args() >= 3) {
211+
$noDeprecation = func_get_arg(2);
212+
}
213+
214+
if (!$first && !$noDeprecation) {
215+
@trigger_error(sprintf('Passing "false" as the second argument to %s() is deprecated as of 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
216+
}
217+
209218
if (!isset($this->bundleMap[$name])) {
210219
throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your %s.php file?', $name, get_class($this)));
211220
}
@@ -241,7 +250,7 @@ public function locateResource($name, $dir = null, $first = true)
241250
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
242251
$overridePath = substr($path, 9);
243252
$resourceBundle = null;
244-
$bundles = $this->getBundle($bundleName, false);
253+
$bundles = $this->getBundle($bundleName, false, true);
245254
$files = array();
246255

247256
foreach ($bundles as $bundle) {
@@ -468,6 +477,8 @@ protected function initializeBundles()
468477
$this->bundles[$name] = $bundle;
469478

470479
if ($parentName = $bundle->getParent()) {
480+
@trigger_error('Bundle inheritance is deprecated as of 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
481+
471482
if (isset($directChildren[$parentName])) {
472483
throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
473484
}

‎src/Symfony/Component/HttpKernel/KernelInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/KernelInterface.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public function getBundles();
6060
/**
6161
* Returns a bundle and optionally its descendants by its name.
6262
*
63+
* The second argument is deprecated as of 3.4 and will be removed in 4.0. This method
64+
* will always return an instance of BundleInterface in 4.0.
65+
*
6366
* @param string $name Bundle name
6467
* @param bool $first Whether to return the first bundle only or together with its descendants
6568
*

‎src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/KernelTest.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ public function testLocateResourceReturnsTheFirstThatMatches()
410410
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt'));
411411
}
412412

413+
/**
414+
* @group legacy
415+
*/
413416
public function testLocateResourceReturnsTheFirstThatMatchesWithParent()
414417
{
415418
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
@@ -426,6 +429,9 @@ public function testLocateResourceReturnsTheFirstThatMatchesWithParent()
426429
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/bar.txt', $kernel->locateResource('@ParentAABundle/bar.txt'));
427430
}
428431

432+
/**
433+
* @group legacy
434+
*/
429435
public function testLocateResourceReturnsAllMatches()
430436
{
431437
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
@@ -444,6 +450,9 @@ public function testLocateResourceReturnsAllMatches()
444450
$kernel->locateResource('@Bundle1Bundle/foo.txt', null, false));
445451
}
446452

453+
/**
454+
* @group legacy
455+
*/
447456
public function testLocateResourceReturnsAllMatchesBis()
448457
{
449458
$kernel = $this->getKernel(array('getBundle'));
@@ -492,6 +501,9 @@ public function testLocateResourceReturnsTheDirOneForResources()
492501
);
493502
}
494503

504+
/**
505+
* @group legacy
506+
*/
495507
public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes()
496508
{
497509
$kernel = $this->getKernel(array('getBundle'));
@@ -508,6 +520,9 @@ public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes()
508520
);
509521
}
510522

523+
/**
524+
* @group legacy
525+
*/
511526
public function testLocateResourceOverrideBundleAndResourcesFolders()
512527
{
513528
$parent = $this->getBundle(__DIR__.'/Fixtures/BaseBundle', null, 'BaseBundle', 'BaseBundle');
@@ -581,6 +596,9 @@ public function testLocateResourceOnDirectories()
581596
);
582597
}
583598

599+
/**
600+
* @group legacy
601+
*/
584602
public function testInitializeBundles()
585603
{
586604
$parent = $this->getBundle(null, null, 'ParentABundle');
@@ -599,6 +617,9 @@ public function testInitializeBundles()
599617
$this->assertEquals(array($child, $parent), $map['ParentABundle']);
600618
}
601619

620+
/**
621+
* @group legacy
622+
*/
602623
public function testInitializeBundlesSupportInheritanceCascade()
603624
{
604625
$grandparent = $this->getBundle(null, null, 'GrandParentBBundle');
@@ -621,6 +642,7 @@ public function testInitializeBundlesSupportInheritanceCascade()
621642
}
622643

623644
/**
645+
* @group legacy
624646
* @expectedException \LogicException
625647
* @expectedExceptionMessage Bundle "ChildCBundle" extends bundle "FooBar", which is not registered.
626648
*/
@@ -631,6 +653,9 @@ public function testInitializeBundlesThrowsExceptionWhenAParentDoesNotExists()
631653
$kernel->boot();
632654
}
633655

656+
/**
657+
* @group legacy
658+
*/
634659
public function testInitializeBundlesSupportsArbitraryBundleRegistrationOrder()
635660
{
636661
$grandparent = $this->getBundle(null, null, 'GrandParentCBundle');
@@ -653,6 +678,7 @@ public function testInitializeBundlesSupportsArbitraryBundleRegistrationOrder()
653678
}
654679

655680
/**
681+
* @group legacy
656682
* @expectedException \LogicException
657683
* @expectedExceptionMessage Bundle "ParentCBundle" is directly extended by two bundles "ChildC2Bundle" and "ChildC1Bundle".
658684
*/
@@ -667,6 +693,7 @@ public function testInitializeBundlesThrowsExceptionWhenABundleIsDirectlyExtende
667693
}
668694

669695
/**
696+
* @group legacy
670697
* @expectedException \LogicException
671698
* @expectedExceptionMessage Trying to register two bundles with the same name "DuplicateName"
672699
*/
@@ -680,6 +707,7 @@ public function testInitializeBundleThrowsExceptionWhenRegisteringTwoBundlesWith
680707
}
681708

682709
/**
710+
* @group legacy
683711
* @expectedException \LogicException
684712
* @expectedExceptionMessage Bundle "CircularRefBundle" can not extend itself.
685713
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.