8000 feature #24161 [HttpKernel] Remove bundle inheritance (fabpot) · symfony/symfony@92d5134 · GitHub
[go: up one dir, main page]

Skip to content

Commit 92d5134

Browse files
committed
feature #24161 [HttpKernel] Remove bundle inheritance (fabpot)
This PR was merged into the 4.0-dev branch. Discussion ---------- [HttpKernel] Remove bundle inheritance | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Blocked by #24160 Commits ------- a8a0a21 [HttpKernel] removed bundle inheritance
2 parents d47b833 + a8a0a21 commit 92d5134

File tree

14 files changed

+50
-481
lines changed

14 files changed

+50
-481
lines changed

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,47 +52,32 @@ public function parse($controller)
5252
}
5353

5454
$originalController = $controller;
55-
list($bundle, $controller, $action) = $parts;
55+
list($bundleName, $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-
if (!is_array($allBundles)) {
77-
// happens when HttpKernel is version 4+
78-
$allBundles = array($allBundles);
75+
$try = $bundle->getNamespace().'\\Controller\\'.$controller.'Controller';
76+
if (class_exists($try)) {
77+
return $try.'::'.$action.'Action';
7978
}
8079

81-
foreach ($allBundles as $b) {
82-
$try = $b->getNamespace().'\\Controller\\'.$controller.'Controller';
83-
if (class_exists($try)) {
84-
return $try.'::'.$action.'Action';
85-
}
86-
87-
$bundles[] = $b->getName();
88-
$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);
89-
}
90-
91-
if (count($bundles) > 1) {
92-
$msg = sprintf('Unable to find controller "%s:%s" in bundles %s.', $bundle, $controller, implode(', ', $bundles));
93-
}
94-
95-
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));
9681
}
9782

9883
/**

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public function testParse()
4040

4141
$this->assertEquals('TestBundle\FooBundle\Controller\DefaultController::indexAction', $parser->parse('FooBundle:Default:index'), '->parse() converts a short a:b:c notation string to a class::method string');
4242
$this->assertEquals('TestBundle\FooBundle\Controller\Sub\DefaultController::indexAction', $parser->parse('FooBundle:Sub\Default:index'), '->parse() converts a short a:b:c notation string to a class::method string');
43-
$this->assertEquals('TestBundle\Fabpot\FooBundle\Controller\DefaultController::indexAction', $parser->parse('SensioFooBundle:Default:index'), '->parse() converts a short a:b:c notation string to a class::method string');
4443
$this->assertEquals('TestBundle\Sensio\Cms\FooBundle\Controller\DefaultController::indexAction', $parser->parse('SensioCmsFooBundle:Default:index'), '->parse() converts a short a:b:c notation string to a class::method string');
4544
$this->assertEquals('TestBundle\FooBundle\Controller\Test\DefaultController::indexAction', $parser->parse('FooBundle:Test\\Default:index'), '->parse() converts a short a:b:c notation string to a class::method string');
4645
$this->assertEquals('TestBundle\FooBundle\Controller\Test\DefaultController::indexAction', $parser->parse('FooBundle:Test/Default:index'), '->parse() converts a short a:b:c notation string to a class::method string');
@@ -138,18 +137,15 @@ public function getInvalidBundleNameTests()
138137
{
139138
return array(
140139
'Alternative will be found using levenshtein' => array('FoodBundle:Default:index', 'FooBundle:Default:index'),
141-
'Alternative will be found using partial match' => array('FabpotFooBund:Default:index', 'FabpotFooBundle:Default:index'),
142140
'Bundle does not exist at all' => array('CrazyBundle:Default:index', false),
143141
);
144142
}
145143

146144
private function createParser()
147145
{
148146
$bundles = array(
149-
'SensioFooBundle' => array($this->getBundle('TestBundle\Fabpot\FooBundle', 'FabpotFooBundle'), $this->getBundle('TestBundle\Sensio\FooBundle', 'SensioFooBundle')),
150-
'SensioCmsFooBundle' => array($this->getBundle('TestBundle\Sensio\Cms\FooBundle', 'SensioCmsFooBundle')),
151-
'FooBundle' => array($this->getBundle('TestBundle\FooBundle', 'FooBundle')),
152-
'FabpotFooBundle' => array($this->getBundle('TestBundle\Fabpot\FooBundle', 'FabpotFooBundle'), $this->getBundle('TestBundle\Sensio\FooBundle', 'SensioFooBundle')),
147+
'SensioCmsFooBundle' => $this->getBundle('TestBundle\Sensio\Cms\FooBundle', 'SensioCmsFooBundle'),
148+
'FooBundle' => $this->getBundle('TestBundle\FooBundle', 'FooBundle'),
153149
);
154150

155151
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
@@ -166,11 +162,9 @@ private function createParser()
166162
;
167163

168164
$bundles = array(
169-
'SensioFooBundle' => $this->getBundle('TestBundle\Fabpot\FooBundle', 'FabpotFooBundle'),
170165
'SensioCmsFooBundle' => $this->getBundle('TestBundle\Sensio\Cms\FooBundle', 'SensioCmsFooBundle'),
171166
'FoooooBundle' => $this->getBundle('TestBundle\FooBundle', 'FoooooBundle'),
172167
'FooBundle' => $this->getBundle('TestBundle\FooBundle', 'FooBundle'),
173-
'FabpotFooBundle' => $this->getBundle('TestBundle\Fabpot\FooBundle', 'FabpotFooBundle'),
174168
);
175169
$kernel
176170
->expects($this->any())

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ public function testValidationPaths()
605605

606606
$container = $this->createContainerFromFile('validation_annotations', array(
607607
'kernel.bundles' => array('TestBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle'),
608-
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/TestBundle')),
608+
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle')),
609609
));
610610

611611
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
@@ -641,7 +641,7 @@ public function testValidationPathsUsingCustomBundlePath()
641641

642642
$container = $this->createContainerFromFile('validation_annotations', array(
643643
'kernel.bundles' => array('CustomPathBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\CustomPathBundle'),
644-
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/CustomPathBundle')),
644+
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/CustomPathBundle')),
645645
));
646646

647647
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
@@ -848,7 +848,7 @@ public function testSerializerCacheDisabled()
848848

849849
public function testSerializerMapping()
850850
{
851-
$container = $this->createContainerFromFile('serializer_mapping', array('kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle', 'parent' => null))));
851+
$container = $this->createContainerFromFile('serializer_mapping', array('kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle'))));
852852
$configDir = __DIR__.'/Fixtures/TestBundle/Resources/config';
853853
$expectedLoaders = array(
854854
new Definition(AnnotationLoader::class, array(new Reference('annotation_reader'))),
@@ -980,7 +980,7 @@ protected function createContainer(array $data = array())
980980
{
981981
return new ContainerBuilder(new ParameterBag(array_merge(array(
982982
'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'),
983-
'kernel.bundles_metadata' => array('FrameworkBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..', 'parent' => null)),
983+
'kernel.bundles_metadata' => array('FrameworkBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..')),
984984
'kernel.cache_dir' => __DIR__,
985985
'kernel.project_dir' => __DIR__,
986986
'kernel.debug' => false,

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,9 @@ public function load(array $configs, ContainerBuilder $container)
109109
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $config['paths']);
110110
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $config['paths']);
111111

112-
$bundleHierarchy = $this->getBundleHierarchy($container, $config);
113-
114-
foreach ($bundleHierarchy as $name => $bundle) {
112+
foreach ($this->getBundleTemplatePaths($container, $config) as $name => $paths) {
115113
$namespace = $this->normalizeBundleName($name);
116-
117-
foreach ($bundle['children'] as $child) {
118-
foreach ($bundleHierarchy[$child]['paths'] as $path) {
119-
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
120-
}
121-
}
122-
123-
foreach ($bundle['paths'] as $path) {
114+
foreach ($paths as $path) {
124115
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
125116
}
126117
}
@@ -166,58 +157,24 @@ public function load(array $configs, ContainerBuilder $container)
166157
$container->registerForAutoconfiguration(RuntimeExtensionInterface::class)->addTag('twig.runtime');
167158
}
168159

169-
private function getBundleHierarchy(ContainerBuilder $container, array $config)
160+
private function getBundleTemplatePaths(ContainerBuilder $container, array $config)
170161
{
171162
$bundleHierarchy = array();
172-
173163
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
174-
if (!array_key_exists($name, $bundleHierarchy)) {
175-
$bundleHierarchy[$name] = array(
176-
'paths' => array(),
177-
'parents' => array(),
178-
'children' => array(),
179-
);
180-
}
181-
182164
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views')) {
183-
$bundleHierarchy[$name]['paths'][] = $dir;
165+
$bundleHierarchy[$name][] = $dir;
184166
}
185167
$container->addResource(new FileExistenceResource($dir));
186168

187169
if (file_exists($dir = $container->getParameterBag()->resolveValue($config['default_path']).'/bundles/'.$name)) {
188-
$bundleHierarchy[$name]['paths'][] = $dir;
170+
$bundleHierarchy[$name][] = $dir;
189171
}
190172
$container->addResource(new FileExistenceResource($dir));
191173

192174
if (file_exists($dir = $bundle['path'].'/Resources/views')) {
193-
$bundleHierarchy[$name]['paths'][] = $dir;
175+
$bundleHierarchy[$name][] = $dir;
194176
}
195177
$container->addResource(new FileExistenceResource($dir));
196-
197-
if (!isset($bundle['parent']) || null === $bundle['parent']) {
198-
continue;
199-
}
200-
201-
$bundleHierarchy[$name]['parents'][] = $bundle['parent'];
202-
203-
if (!array_key_exists($bundle['parent'], $bundleHierarchy)) {
204-
$bundleHierarchy[$bundle['parent']] = array(
205-
'paths' => array(),
206-
'parents' => array(),
207-
'children' => array(),
208-
);
209-
}
210-
211-
$bundleHierarchy[$bundle['parent']]['children'] = array_merge($bundleHierarchy[$name]['children'], array($name), $bundleHierarchy[$bundle['parent']]['children']);
212-
213-
foreach ($bundleHierarchy[$bundle['parent']]['parents'] as $parent) {
214-
$bundleHierarchy[$name]['parents'][] = $parent;
215-
$bundleHierarchy[$parent]['children'] = array_merge($bundleHierarchy[$name]['children'], array($name), $bundleHierarchy[$parent]['children']);
216-
}
217-
218-
foreach ($bundleHierarchy[$name]['children'] as $child) {
219-
$bundleHierarchy[$child]['parents'] = array_merge($bundleHierarchy[$child]['parents'], $bundleHierarchy[$name]['parents']);
220-
}
221178
}
222179

223180
return $bundleHierarchy;

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views/layout.html.twig

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views/layout.html.twig

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildTwigBundle/Resources/views/layout.html.twig

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/Bundle/ChildTwigBundle/Resources/views/layout.html.twig

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,9 @@ public function testTwigLoaderPaths($format)
188188
array('namespaced_path1', 'namespace1'),
189189
array('namespaced_path2', 'namespace2'),
190190
array('namespaced_path3', 'namespace3'),
191-
array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildChildChildTwig'),
192-
array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildChildTwig'),
193-
array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildChildChildTwig'),
194-
array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'Twig'),
195-
array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'Twig'),
196-
array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'Twig'),
197-
array(__DIR__.'/Fixtures/Bundle/ChildTwigBundle/Re 10000 sources/views', 'Twig'),
198191
array(__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'),
199192
array(__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'),
200193
array(realpath(__DIR__.'/../..').'/Resources/views', 'Twig'),
201-
array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildTwig'),
202-
array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildTwig'),
203-
array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildTwig'),
204-
array(__DIR__.'/Fixtures/Bundle/ChildTwigBundle/Resources/views', 'ChildTwig'),
205-
array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildTwig'),
206-
array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildChildTwig'),
207-
array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildChildTwig'),
208194
array(__DIR__.'/Fixtures/Resources/views'),
209195
array(__DIR__.'/Fixtures/templates'),
210196
), $paths);
@@ -284,37 +270,12 @@ private function createContainer()
284270
'kernel.debug' => false,
285271
'kernel.bundles' => array(
286272
'TwigBundle' => 'Symfony\\Bundle\\TwigBundle\\TwigBundle',
287-
'ChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildTwigBundle\\ChildTwigBundle',
288-
'ChildChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildTwigBundle\\ChildChildTwigBundle',
289-
'ChildChildChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildTwigBundle\\ChildChildChildTwigBundle',
290-
'ChildChildChildChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildChildTwigBundle\\ChildChildChildChildTwigBundle',
291273
),
292274
'kernel.bundles_metadata' => array(
293-
'ChildChildChildChildTwigBundle' => array(
294-
'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildChildTwigBundle\\ChildChildChildChildTwigBundle',
295-
'parent' => 'ChildChildChildTwigBundle',
296-
'path' => __DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle',
297-
),
298275
'TwigBundle' => array(
299276
'namespace' => 'Symfony\\Bundle\\TwigBundle',
300-
'parent' => null,
301277
'path' => realpath(__DIR__.'/../..'),
302278
),
303-
'ChildTwigBundle' => array(
304-
'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildTwigBundle\\ChildTwigBundle',
305-
'parent' => 'TwigBundle',
306-
'path' => __DIR__.'/Fixtures/Bundle/ChildTwigBundle',
307-
),
308-
'ChildChildChildTwigBundle' => array(
309-
'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildTwigBundle\\ChildChildChildTwigBundle',
310-
'parent' => 'ChildChildTwigBundle',
311-
'path' => __DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle',
312-
),
313-
'ChildChildTwigBundle' => array(
314-
'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildTwigBundle\\ChildChildTwigBundle',
315-
'parent' => 'ChildTwigBundle',
316-
'path' => __DIR__.'/Fixtures/Bundle/ChildChildTwigBundle',
317-
),
318279
),
319280
)));
320281

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
*

0 commit comments

Comments
 (0)
0