8000 [HttpKernel] Deprecate bundle inheritance by fabpot · Pull Request #24160 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Deprecate bundle inheritance #24160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADE-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ FrameworkBundle
HttpKernel
----------

* Bundle inheritance has been deprecated.

* Relying on convention-based commands discovery has been deprecated and
won't be supported in 4.0. Use PSR-4 based service discovery instead.

Expand Down
2 changes: 2 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ HttpFoundation
HttpKernel
----------

* Bundle inheritance has been removed.

* Relying on convention-based commands discovery is not supported anymore.
Use PSR-4 based service discovery instead.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function parse($controller)

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

$lev = levenshtein($nonExistentBundleName, $bundleName);
if ($lev <= strlen($nonExistentBundleName) / 3 && ($alternative === null || $lev < $shortest)) {
if ($lev <= strlen($nonExistentBundleName) / 3 && (null === $alternative || $lev < $shortest)) {
$alternative = $bundleName;
$shortest = $lev;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function getContainerExtension();
* bundle.
*
* @return string The Bundle name it overrides or null if no parent
*
* @deprecated This method is deprecated as of 3.4 and will be removed in 4.0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to drop the final dot here according to the latest CS changes?

Sorry, something went wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most @deprecated tags have a dot at the end currently. As this is a sentence, I think that's the way it should be.

*/
public function getParent();

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
3.4.0
-----

* deprecated bundle inheritance
* added `RebootableInterface` and implemented it in `Kernel`
* deprecated commands auto registration
* added `AddCacheClearerPass`
Expand Down
17 changes: 14 additions & 3 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,17 @@ public function getBundles()
/**
* {@inheritdoc}
*/
public function getBundle($name, $first = true)
public function getBundle($name, $first = true/*, $noDeprecation = false */)
{
$noDeprecation = false;
if (func_num_args() >= 3) {
$noDeprecation = func_get_arg(2);
}

if (!$first && !$noDeprecation) {
@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);
}

if (!isset($this->bundleMap[$name])) {
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)));
}
Expand Down Expand Up @@ -241,7 +250,7 @@ public function locateResource($name, $dir = null, $first = true)
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
$overridePath = substr($path, 9);
$resourceBundle = null;
$bundles = $this->getBundle($bundleName, false);
$bundles = $this->getBundle($bundleName, false, true);
$files = array();

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

if ($parentName = $bundle->getParent()) {
@trigger_error('Bundle inheritance is deprecated as of 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);

if (isset($directChildren[$parentName])) {
throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
}
Expand Down Expand Up @@ -852,7 +863,7 @@ public static function stripComments($source)
do {
$token = $tokens[++$i];
$output .= isset($token[1]) && 'b"' !== $token ? $token[1] : $token;
} while ($token[0] !== T_END_HEREDOC);
} while (T_END_HEREDOC !== $token[0]);
$rawChunk = '';
} elseif (T_WHITESPACE === $token[0]) {
if ($ignoreSpace) {
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/HttpKernel/KernelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function getBundles();
/**
* Returns a bundle and optionally its descendants by its name.
*
* The second argument is deprecated as of 3.4 and will be removed in 4.0. This method
* will always return an instance of BundleInterface in 4.0.
*
* @param string $name Bundle name
* @param bool $first Whether to return the first bundle only or together with its descendants
*
Expand Down
28 changes: 28 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ public function testLocateResourceReturnsTheFirstThatMatches()
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt'));
}

/**
* @group legacy
*/
public function testLocateResourceReturnsTheFirstThatMatchesWithParent()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
Expand All @@ -426,6 +429,9 @@ public function testLocateResourceReturnsTheFirstThatMatchesWithParent()
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/bar.txt', $kernel->locateResource('@ParentAABundle/bar.txt'));
}

/**
* @group legacy
*/
public function testLocateResourceReturnsAllMatches()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
Expand All @@ -444,6 +450,9 @@ public function testLocateResourceReturnsAllMatches()
$kernel->locateResource('@Bundle1Bundle/foo.txt', null, false));
}

/**
* @group legacy
*/
public function testLocateResourceReturnsAllMatchesBis()
{
$kernel = $this->getKernel(array('getBundle'));
Expand Down Expand Up @@ -492,6 +501,9 @@ public function testLocateResourceReturnsTheDirOneForResources()
);
}

/**
* @group legacy
*/
public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes()
{
$kernel = $this->getKernel(array('getBundle'));
Expand All @@ -508,6 +520,9 @@ public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes()
);
}

/**
* @group legacy
*/
public function testLocateResourceOverrideBundleAndResourcesFolders()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/BaseBundle', null, 'BaseBundle', 'BaseBundle');
Expand Down Expand Up @@ -581,6 +596,9 @@ public function testLocateResourceOnDirectories()
);
}

/**
* @group legacy
*/
public function testInitializeBundles()
{
$parent = $this->getBundle(null, null, 'ParentABundle');
Expand All @@ -599,6 +617,9 @@ public function testInitializeBundles()
$this->assertEquals(array($child, $parent), $map['ParentABundle']);
}

/**
* @group legacy
*/
public function testInitializeBundlesSupportInheritanceCascade()
{
$grandparent = $this->getBundle(null, null, 'GrandParentBBundle');
Expand All @@ -621,6 +642,7 @@ public function testInitializeBundlesSupportInheritanceCascade()
}

/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Bundle "ChildCBundle" extends bundle "FooBar", which is not registered.
*/
Expand All @@ -631,6 +653,9 @@ public function testInitializeBundlesThrowsExceptionWhenAParentDoesNotExists()
$kernel->boot();
}

/**
* @group legacy
*/
public function testInitializeBundlesSupportsArbitraryBundleRegistrationOrder()
{
$grandparent = $this->getBundle(null, null, 'GrandParentCBundle');
Expand All @@ -653,6 +678,7 @@ public function testInitializeBundlesSupportsArbitraryBundleRegistrationOrder()
}

/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Bundle "ParentCBundle" is directly extended by two bundles "ChildC2Bundle" and "ChildC1Bundle".
*/
Expand All @@ -667,6 +693,7 @@ public function testInitializeBundlesThrowsExceptionWhenABundleIsDirectlyExtende
}

/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Trying to register two bundles with the same name "DuplicateName"
*/
Expand All @@ -680,6 +707,7 @@ public function testInitializeBundleThrowsExceptionWhenRegisteringTwoBundlesWith
}

/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Bundle "CircularRefBundle" can not extend itself.
*/
Expand Down
0