Skip to content

Commit 080f83e

Browse files
committed
[HttpKernel] removed bundle inheritance
1 parent c1d8833 commit 080f83e

File tree

5 files changed

+31
-135
lines changed

5 files changed

+31
-135
lines changed

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,40 +54,30 @@ public function parse($controller)
5454
$originalController = $controller;
5555
list($bundle, $controller, $action) = $parts;
5656
$controller = str_replace('/', '\\', $controller);
57-
$bundles = array();
5857

5958
try {
6059
// this throws an exception if there is no such bundle
61-
$allBundles = $this->kernel->getBundle($bundle, false, true);
60+
$bundle = $this->kernel->getBundle($bundleName);
6261
} catch (\InvalidArgumentException $e) {
6362
$message = sprintf(
6463
'The "%s" (from the _controller value "%s") does not exist or is not enabled in your kernel!',
65-
$bundle,
64+
$bundleName,
6665
$originalController
6766
);
6867

69-
if ($alternative = $this->findAlternative($bundle)) {
68+
if ($alternative = $this->findAlternative($bundleName)) {
7069
$message .= sprintf(' Did you mean "%s:%s:%s"?', $alternative, $controller, $action);
7170
}
7271

7372
throw new \InvalidArgumentException($message, 0, $e);
7473
}
7574

76-
foreach ($allBundles as $b) {
77-
$try = $b->getNamespace().'\\Controller\\'.$controller.'Controller';
78-
if (class_exists($try)) {
79-
return $try.'::'.$action.'Action';
80-
}
81-
82-
$bundles[] = $b->getName();
83-
$msg = sprintf('The _controller value "%s:%s:%s" maps to a "%s" class, but this class was not found. Create this class or check the spelling of the class and its namespace.', $bundle, $controller, $action, $try);
84-
}
85-
86-
if (count($bundles) > 1) {
87-
$msg = sprintf('Unable to find controller "%s:%s" in bundles %s.', $bundle, $controller, implode(', ', $bundles));
75+
$try = $bundle->getNamespace().'\\Controller\\'.$controller.'Controller';
76+
if (class_exists($try)) {
77+
return $try.'::'.$action.'Action';
8878
}
8979

90-
throw new \InvalidArgumentException($msg);
80+
throw new \InvalidArgumentException(sprintf('The _controller value "%s:%s:%s" maps to a "%s" class, but this class was not found. Create this class or check the spelling of the class and its namespace.', $bundleName, $controller, $action, $try));
9181
}
9282

9383
/**

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,6 @@ public function getPath()
128128
return $this->path;
129129
}
130130

131-
/**
132-
* Returns the bundle parent name.
133-
*
134-
* @return string|null The Bundle parent name it overrides or null if no parent
135-
*/
136-
public function getParent()
137-
{
138-
}
139-
140131
/**
141132
* Returns the bundle name (the class short name).
142133
*

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ public function build(ContainerBuilder $container);
4848
*/
4949
public function getContainerExtension();
5050

51-
/**
52-
* Returns the bundle name that this bundle overrides.
53-
*
54-
* Despite its name, this method does not imply any parent/child relationship
55-
* between the bundles, just a way to extend and override an existing
56-
* bundle.
57-
*
58-
* @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.
61-
*/
62-
public function getParent();
63-
6451
/**
6552
* Returns the bundle name (the class short name).
6653
*

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 20 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
4848
*/
4949
protected $bundles = array();
5050

51-
protected $bundleMap;
5251
protected $container;
5352
protected $rootDir;
5453
protected $environment;
@@ -197,26 +196,13 @@ public function getBundles()
197196
/**
198197
* {@inheritdoc}
199198
*/
200-
public function getBundle($name, $first = true/*, $noDeprecation = false */)
199+
public function getBundle($name)
201200
{
202-
$noDeprecation = false;
203-
if (func_num_args() >= 3) {
204-
$noDeprecation = func_get_arg(2);
205-
}
206-
207-
if (!$first && !$noDeprecation) {
208-
@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);
209-
}
210-
211-
if (!isset($this->bundleMap[$name])) {
201+
if (!isset($this->bundles[$name])) {
212202
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)));
213203
}
214204

215-
if (true === $first) {
216-
return $this->bundleMap[$name][0];
217-
}
218-
219-
return $this->bundleMap[$name];
205+
return $this->bundles[$name];
220206
}
221207

222208
/**
@@ -243,32 +229,27 @@ public function locateResource($name, $dir = null, $first = true)
243229
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
244230
$overridePath = substr($path, 9);
245231
$resourceBundle = null;
246-
$bundles = $this->getBundle($bundleName, false, true);
232+
$bundle = $this->getBundle($bundleName);
247233
$files = array();
248234

249-
foreach ($bundles as $bundle) {
250-
if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
251-
if (null !== $resourceBundle) {
252-
throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.',
253-
$file,
254-
$resourceBundle,
255-
$dir.'/'.$bundles[0]->getName().$overridePath
256-
));
257-
}
258-
259-
if ($first) {
260-
return $file;
261-
}
262-
$files[] = $file;
235+
if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
236+
if (null !== $resourceBundle) {
237+
throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.',
238+
$file,
239+
$resourceBundle,
240+
$dir.'/'.$bundles[0]->getName().$overridePath
241+
));
263242
}
264243

265-
if (file_exists($file = $bundle->getPath().'/'.$path)) {
266-
if ($first && !$isResource) {
267-
return $file;
268-
}
269-
$files[] = $file;
270-
$resourceBundle = $bundle->getName();
244+
$files[] = $file;
245+
}
246+
247+
if (file_exists($file = $bundle->getPath().'/'.$path)) {
248+
if ($first && !$isResource) {
249+
return $file;
271250
}
251+
$files[] = $file;
252+
$resourceBundle = $bundle->getName();
272253
}
273254

274255
if (count($files) > 0) {
@@ -393,68 +374,20 @@ public function getCharset()
393374
}
394375

395376
/**
396-
* Initializes the data structures related to the bundle management.
397-
*
398-
* - the bundles property maps a bundle name to the bundle instance,
399-
* - the bundleMap property maps a bundle name to the bundle inheritance hierarchy (most derived bundle first).
377+
* Initializes bundles.
400378
*
401379
* @throws \LogicException if two bundles share a common name
402-
* @throws \LogicException if a bundle tries to extend a non-registered bundle
403-
* @throws \LogicException if a bundle tries to extend itself
404-
* @throws \LogicException if two bundles extend the same ancestor
405380
*/
406381
protected function initializeBundles()
407382
{
408383
// init bundles
409384
$this->bundles = array();
410-
$topMostBundles = array();
411-
$directChildren = array();
412-
413385
foreach ($this->registerBundles() as $bundle) {
414386
$name = $bundle->getName();
415387
if (isset($this->bundles[$name])) {
416388
throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
417389
}
418390
$this->bundles[$name] = $bundle;
419-
420-
if ($parentName = $bundle->getParent()) {
421-
@trigger_error('Bundle inheritance is deprecated as of 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
422-
423-
if (isset($directChildren[$parentName])) {
424-
throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
425-
}
426-
if ($parentName == $name) {
427-
throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
428-
}
429-
$directChildren[$parentName] = $name;
430-
} else {
431-
$topMostBundles[$name] = $bundle;
432-
}
433-
}
434-
435-
// look for orphans
436-
if (!empty($directChildren) && count($diff = array_diff_key($directChildren, $this->bundles))) {
437-
$diff = array_keys($diff);
438-
439-
throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
440-
}
441-
442-
// inheritance
443-
$this->bundleMap = array();
444-
foreach ($topMostBundles as $name => $bundle) {
445-
$bundleMap = array($bundle);
446-
$hierarchy = array($name);
447-
448-
while (isset($directChildren[$name])) {
449-
$name = $directChildren[$name];
450-
array_unshift($bundleMap, $this->bundles[$name]);
451-
$hierarchy[] = $name;
452-
}
453-
454-
foreach ($hierarchy as $hierarchyBundle) {
455-
$this->bundleMap[$hierarchyBundle] = $bundleMap;
456-
array_pop($bundleMap);
457-
}
458391
}
459392
}
460393

@@ -586,7 +519,6 @@ protected function getKernelParameters()
586519
foreach ($this->bundles as $name => $bundle) {
587520
$bundles[$name] = get_class($bundle);
588521
$bundlesMetadata[$name] = array(
589-
'parent' => $bundle->getParent(),
590522
'path' => $bundle->getPath(),
591523
'namespace' => $bundle->getNamespace(),
592524
);

src/Symfony/Component/HttpKernel/KernelInterface.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,15 @@ public function shutdown();
5858
public function getBundles();
5959

6060
/**
61-
* Returns a bundle and optionally its descendants by its name.
61+
* Returns a bundle.
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.
63+
* @param string $name Bundle name
6564
*
66-
* @param string $name Bundle name
67-
* @param bool $first Whether to return the first bundle only or together with its descendants
68-
*
69-
* @return BundleInterface|BundleInterface[] A BundleInterface instance or an array of BundleInterface instances if $first is false
65+
* @return BundleInterface A BundleInterface instance
7066
*
7167
* @throws \InvalidArgumentException when the bundle is not enabled
7268
*/
73-
public function getBundle($name, $first = true);
69+
public function getBundle($name);
7470

7571
/**
7672
* Returns the file path for a given resource.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy