Skip to content

Commit 654a87c

Browse files
committed
Merge branch '2.8' into 3.1
* 2.8: Fix serializer/translations/validator resources loading for bundles overriding getPath()
2 parents 20495a2 + 0134001 commit 654a87c

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
@@ -690,12 +690,11 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
690690
$dirs[] = dirname(dirname($r->getFileName())).'/Resources/translations';
691691
}
692692
$rootDir = $container->getParameter('kernel.root_dir');
693-
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
694-
$reflection = new \ReflectionClass($class);
695-
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
693+
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
694+
if (is_dir($dir = $bundle['path'].'/Resources/translations')) {
696695
$dirs[] = $dir;
697696
}
698-
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) {
697+
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
699698
$dirs[] = $dir;
700699
}
701700
}
@@ -810,11 +809,8 @@ private function getValidatorMappingFiles(ContainerBuilder $container)
810809
$container->addResource(new FileResource($files[0][0]));
811810
}
812811

813-
$bundles = $container->getParameter('kernel.bundles');
814-
foreach ($bundles as $bundle) {
815-
$reflection = new \ReflectionClass($bundle);
816-
$dirname = dirname($reflection->getFileName());
817-
812+
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
813+
$dirname = $bundle['path'];
818814
if (is_file($file = $dirname.'/Resources/config/validation.xml')) {
819815
$files[0][] = $file;
820816
$container->addResource(new FileResource($file));
@@ -947,10 +943,8 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
947943
$serializerLoaders[] = $annotationLoader;
948944
}
949945

950-
$bundles = $container->getParameter('kernel.bundles');
951-
foreach ($bundles as $bundle) {
952-
$reflection = new \ReflectionClass($bundle);
953-
$dirname = dirname($reflection->getFileName());
946+
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
947+
$dirname = $bundle['path'];
954948

955949
if (is_file($file = $dirname.'/Resources/config/serialization.xml')) {
956950
$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
@@ -375,7 +375,8 @@ public function testValidationPaths()
375375
require_once __DIR__.'/Fixtures/TestBundle/TestBundle.php';
376376

377377
$container = $this->createContainerFromFile('validation_annotations', array(
378-
'kernel.bundles' => array('TestBundle' => 'Symfony\Bundle\FrameworkBundle\Tests\TestBundle'),
378+
'kernel.bundles' => array('TestBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle'),
379+
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/TestBundle')),
379380
));
380381

381382
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
@@ -405,6 +406,33 @@ public function testValidationPaths()
405406
$this->assertStringEndsWith('TestBundle/Resources/config/validation.yml', $yamlMappings[0]);
406407
}
407408

409+
public function testValidationPathsUsingCustomBundlePath()
410+
{
411+
require_once __DIR__.'/Fixtures/CustomPathBundle/src/CustomPathBundle.php';
412+
413+
$container = $this->createContainerFromFile('validation_annotations', array(
414+
'kernel.bundles' => array('CustomPathBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\CustomPathBundle'),
415+
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/CustomPathBundle')),
416+
));
417+
418+
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
419+
$xmlMappings = $calls[3][1][0];
420+
$this->assertCount(2, $xmlMappings);
421+
422+
try {
423+
// Testing symfony/symfony
424+
$this->assertStringEndsWith('Component'.DIRECTORY_SEPARATOR.'Form/Resources/config/validation.xml', $xmlMappings[0]);
425+
} catch (\Exception $e) {
426+
// Testing symfony/framework-bundle with deps=high
427+
$this->assertStringEndsWith('symfony'.DIRECTORY_SEPARATOR.'form/Resources/config/validation.xml', $xmlMappings[0]);
428+
}
429+
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.xml', $xmlMappings[1]);
430+
431+
$yamlMappings = $calls[4][1][0];
432+
$this->assertCount(1, $yamlMappings);
433+
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.yml', $yamlMappings[0]);
434+
}
435+
408436
public function testValidationNoStaticMethod()
409437
{
410438
$container = $this->createContainerFromFile('validation_no_static_method');
@@ -630,6 +658,7 @@ protected function createContainer(array $data = array())
630658
{
631659
return new ContainerBuilder(new ParameterBag(array_merge(array(
632660
'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'),
661+
'kernel.bundles_metadata' => array('FrameworkBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..', 'parent' => null)),
633662
'kernel.cache_dir' => __DIR__,
634663
'kernel.debug' => false,
635664
'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/config": "~2.8|~3.0",
2525
"symfony/event-dispatcher": "~2.8|~3.0",
2626
"symfony/http-foundation": "~3.1",
27-
"symfony/http-kernel": "~3.1.2|~3.2",
27+
"symfony/http-kernel": "~3.1.9|^3.2.2",
2828
"symfony/polyfill-mbstring": "~1.0",
2929
"symfony/filesystem": "~2.8|~3.0",
3030
"symfony/finder": "~2.8|~3.0",

0 commit comments

Comments
 (0)