Skip to content

Commit 829b6bd

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Fix serializer/translations/validator resources loading for bundles overriding getPath()
2 parents 1fc445a + da88e6b commit 829b6bd

File tree

10 files changed

+73
-22
lines changed

10 files changed

+73
-22
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,11 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
696696
$dirs[] = dirname(dirname($r->getFileName())).'/Resources/translations';
697697
}
698698
$rootDir = $container->getParameter('kernel.root_dir');
699-
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
700-
$reflection = new \ReflectionClass($class);
701-
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
699+
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
700+
if (is_dir($dir = $bundle['path'].'/Resources/translations')) {
702701
$dirs[] = $dir;
703702
}
704-
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) {
703+
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
705704
$dirs[] = $dir;
706705
}
707706
}
@@ -822,11 +821,8 @@ private function getValidatorMappingFiles(ContainerBuilder $container)
822821
$container->addResource(new FileResource($files[0][0]));
823822
}
824823

825-
$bundles = $container->getParameter('kernel.bundles');
826-
foreach ($bundles as $bundle) {
827-
$reflection = new \ReflectionClass($bundle);
828-
$dirname = dirname($reflection->getFileName());
829-
824+
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
825+
$dirname = $bundle['path'];
830826
if (is_file($file = $dirname.'/Resources/config/validation.xml')) {
831827
$files[0][] = $file;
832828
$container->addResource(new FileResource($file));
@@ -944,10 +940,8 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
944940
$serializerLoaders[] = $annotationLoader;
945941
}
946942

947-
$bundles = $container->getParameter('kernel.bundles');
948-
foreach ($bundles as $bundle) {
949-
$reflection = new \ReflectionClass($bundle);
950-
$dirname = dirname($reflection->getFileName());
943+
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
944+
$dirname = $bundle['path'];
951945

952946
if (is_file($file = $dirname.'/Resources/config/serialization.xml')) {
953947
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', array($file));

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/CustomPathBundle/Resources/config/validation.xml

Whitespace-only changes.

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/CustomPathBundle/Resources/config/validation.yml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests;
13+
14+
class CustomPathBundle extends \Symfony\Component\HttpKernel\Bundle\Bundle
15+
{
16+
public function getPath()
17+
{
18+
return __DIR__.'/..';
19+
}
20+
}

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ public function testValidationPaths()
350350
require_once __DIR__.'/Fixtures/TestBundle/TestBundle.php';
351351

352352
$container = $this->createContainerFromFile('validation_annotations', array(
353-
'kernel.bundles' => array('TestBundle' => 'Symfony\Bundle\FrameworkBundle\Tests\TestBundle'),
353+
'kernel.bundles' => array('TestBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle'),
354+
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/TestBundle')),
354355
));
355356

356357
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
@@ -378,6 +379,33 @@ public function testValidationPaths()
378379
$this->assertStringEndsWith('TestBundle/Resources/config/validation.yml', $yamlMappings[0]);
379380
}
380381

382+
public function testValidationPathsUsingCustomBundlePath()
383+
{
384+
require_once __DIR__.'/Fixtures/CustomPathBundle/src/CustomPathBundle.php';
385+
386+
$container = $this->createContainerFromFile('validation_annotations', array(
387+
'kernel.bundles' => array('CustomPathBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\CustomPathBundle'),
388+
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/CustomPathBundle')),
389+
));
390+
391+
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
392+
$xmlMappings = $calls[3][1][0];
393+
$this->assertCount(2, $xmlMappings);
394+
395+
try {
396+
// Testing symfony/symfony
397+
$this->assertStringEndsWith('Component'.DIRECTORY_SEPARATOR.'Form/Resources/config/validation.xml', $xmlMappings[0]);
398+
} catch (\Exception $e) {
399+
// Testing symfony/framework-bundle with deps=high
400+
$this->assertStringEndsWith('symfony'.DIRECTORY_SEPARATOR.'form/Resources/config/validation.xml', $xmlMappings[0]);
401+
}
402+
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.xml', $xmlMappings[1]);
403+
404+
$yamlMappings = $calls[4][1][0];
405+
$this->assertCount(1, $yamlMappings);
406+
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.yml', $yamlMappings[0]);
407+
}
408+
381409
public function testValidationNoStaticMethod()
382410
{
383411
$container = $this->createContainerFromFile('validation_no_static_method');
@@ -513,6 +541,7 @@ protected function createContainer(array $data = array())
513541
{
514542
return new ContainerBuilder(new ParameterBag(array_merge(array(
515543
'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'),
544+
'kernel.bundles_metadata' => array('FrameworkBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..', 'parent' => null)),
516545
'kernel.cache_dir' => __DIR__,
517546
'kernel.debug' => false,
518547
'kernel.environment' => 'test',

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"symfony/event-dispatcher": "~2.8|~3.0.0",
2525
"symfony/finder": "~2.0,>=2.0.5|~3.0.0",
2626
"symfony/http-foundation": "~2.7",
27-
"symfony/http-kernel": "~2.8.8",
27+
"symfony/http-kernel": "~2.8.16",
2828
"symfony/polyfill-mbstring": "~1.0",
2929
"symfony/filesystem": "~2.3|~3.0.0",
3030
"symfony/routing": "~2.8|~3.0.0",

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,16 @@ public function load(array $configs, ContainerBuilder $container)
9393
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $config['paths']);
9494

9595
// register bundles as Twig namespaces
96-
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
97-
$dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views';
96+
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
97+
$dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views';
9898
if (is_dir($dir)) {
99-
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
99+
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $name);
100100
}
101101
$container->addResource(new FileExistenceResource($dir));
102102

103-
$reflection = new \ReflectionClass($class);
104-
$dir = dirname($reflection->getFileName()).'/Resources/views';
103+
$dir = $bundle['path'].'/Resources/views';
105104
if (is_dir($dir)) {
106-
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
105+
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $name);
107106
}
108107
$container->addResource(new FileExistenceResource($dir));
109108
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ private function createContainer()
255255
'kernel.charset' => 'UTF-8',
256256
'kernel.debug' => false,
257257
'kernel.bundles' => array('TwigBundle' => 'Symfony\\Bundle\\TwigBundle\\TwigBundle'),
258+
'kernel.bundles_metadata' => array('TwigBundle' => array('namespace' => 'Symfony\\Bundle\\TwigBundle', 'parent' => null, 'path' => realpath(__DIR__.'/../..'))),
258259
)));
259260

260261
return $container;

src/Symfony/Bundle/TwigBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/asset": "~2.7|~3.0.0",
2121
"symfony/twig-bridge": "~2.7|~3.0.0",
2222
"symfony/http-foundation": "~2.5|~3.0.0",
23-
"symfony/http-kernel": "~2.7",
23+
"symfony/http-kernel": "~2.7.23|~2.8.16"
2424
"twig/twig": "~1.28|~2.0"
2525
},
2626
"require-dev": {

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,15 @@ protected function initializeContainer()
532532
protected function getKernelParameters()
533533
{
534534
$bundles = array();
535+
$bundlesMetadata = array();
536+
535537
foreach ($this->bundles as $name => $bundle) {
536538
$bundles[$name] = get_class($bundle);
539+
$bundlesMetadata[$name] = array(
540+
'parent' => $bundle->getParent(),
541+
'path' => $bundle->getPath(),
542+
'namespace' => $bundle->getNamespace(),
543+
);
537544
}
538545

539546
return array_merge(
@@ -545,6 +552,7 @@ protected function getKernelParameters()
545552
'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(),
546553
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
547554
'kernel.bundles' => $bundles,
555+
'kernel.bundles_metadata' => $bundlesMetadata,
548556
'kernel.charset' => $this->getCharset(),
549557
'kernel.container_class' => $this->getContainerClass(),
550558
),

0 commit comments

Comments
 (0)