Skip to content

Commit 0134001

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Fix serializer/translations/validator resources loading for bundles overriding getPath()
2 parents 58dc3c9 + 9eb0d51 commit 0134001

File tree

6 files changed

+58
-15
lines changed

6 files changed

+58
-15
lines changed

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));

Tests/DependencyInjection/Fixtures/CustomPathBundle/Resources/config/validation.xml

Whitespace-only changes.

Tests/DependencyInjection/Fixtures/CustomPathBundle/Resources/config/validation.yml

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
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+
}

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',

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",

0 commit comments

Comments
 (0)