Skip to content

Commit 7d1ee8d

Browse files
committed
Merge branch '3.1' into 3.2
* 3.1: Fix serializer/translations/validator resources loading for bundles overriding getPath()
2 parents af8dddc + 654a87c commit 7d1ee8d

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
@@ -845,12 +845,11 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
845845
$dirs[] = dirname(dirname($r->getFileName())).'/Resources/translations';
846846
}
847847
$rootDir = $container->getParameter('kernel.root_dir');
848-
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
849-
$reflection = new \ReflectionClass($class);
850-
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
848+
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
849+
if (is_dir($dir = $bundle['path'].'/Resources/translations')) {
851850
$dirs[] = $dir;
852851
}
853-
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) {
852+
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
854853
$dirs[] = $dir;
855854
}
856855
}
@@ -973,11 +972,8 @@ private function getValidatorMappingFiles(ContainerBuilder $container)
973972
$container->addResource(new FileResource($files[0][0]));
974973
}
975974

976-
$bundles = $container->getParameter('kernel.bundles');
977-
foreach ($bundles as $bundle) {
978-
$reflection = new \ReflectionClass($bundle);
979-
$dirname = dirname($reflection->getFileName());
980-
975+
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
976+
$dirname = $bundle['path'];
981977
if (is_file($file = $dirname.'/Resources/config/validation.xml')) {
982978
$files[0][] = $file;
983979
$container->addResource(new FileResource($file));
@@ -1150,10 +1146,8 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
11501146
$serializerLoaders[] = $annotationLoader;
11511147
}
11521148

1153-
$bundles = $container->getParameter('kernel.bundles');
1154-
foreach ($bundles as $bundle) {
1155-
$reflection = new \ReflectionClass($bundle);
1156-
$dirname = dirname($reflection->getFileName());
1149+
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
1150+
$dirname = $bundle['path'];
11571151

11581152
if (is_file($file = $dirname.'/Resources/config/serialization.xml')) {
11591153
$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
@@ -472,7 +472,8 @@ public function testValidationPaths()
472472
require_once __DIR__.'/Fixtures/TestBundle/TestBundle.php';
473473

474474
$container = $this->createContainerFromFile('validation_annotations', array(
475-
'kernel.bundles' => array('TestBundle' => 'Symfony\Bundle\FrameworkBundle\Tests\TestBundle'),
475+
'kernel.bundles' => array('TestBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle'),
476+
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/TestBundle')),
476477
));
477478

478479
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
@@ -502,6 +503,33 @@ public function testValidationPaths()
502503
$this->assertStringEndsWith('TestBundle/Resources/config/validation.yml', $yamlMappings[0]);
503504
}
504505

506+
public function testValidationPathsUsingCustomBundlePath()
507+
{
508+
require_once __DIR__.'/Fixtures/CustomPathBundle/src/CustomPathBundle.php';
509+
510+
$container = $this->createContainerFromFile('validation_annotations', array(
511+
'kernel.bundles' => array('CustomPathBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\CustomPathBundle'),
512+
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/CustomPathBundle')),
513+
));
514+
515+
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
516+
$xmlMappings = $calls[3][1][0];
517+
$this->assertCount(2, $xmlMappings);
518+
519+
try {
520+
// Testing symfony/symfony
521+
$this->assertStringEndsWith('Component'.DIRECTORY_SEPARATOR.'Form/Resources/config/validation.xml', $xmlMappings[0]);
522+
} catch (\Exception $e) {
523+
// Testing symfony/framework-bundle with deps=high
524+
$this->assertStringEndsWith('symfony'.DIRECTORY_SEPARATOR.'form/Resources/config/validation.xml', $xmlMappings[0]);
525+
}
526+
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.xml', $xmlMappings[1]);
527+
528+
$yamlMappings = $calls[4][1][0];
529+
$this->assertCount(1, $yamlMappings);
530+
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.yml', $yamlMappings[0]);
531+
}
532+
505533
public function testValidationNoStaticMethod()
506534
{
507535
$container = $this->createContainerFromFile('validation_no_static_method');
@@ -763,6 +791,7 @@ protected function createContainer(array $data = array())
763791
{
764792
return new ContainerBuilder(new ParameterBag(array_merge(array(
765793
'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'),
794+
'kernel.bundles_metadata' => array('FrameworkBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..', 'parent' => null)),
766795
'kernel.cache_dir' => __DIR__,
767796
'kernel.debug' => false,
768797
'kernel.environment' => 'test',

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/event-dispatcher": "~2.8|~3.0",
2525
"symfony/http-foundation": "~3.1",
26-
"symfony/http-kernel": "~3.2",
26+
"symfony/http-kernel": "~3.2.2|~3.3",
2727
"symfony/polyfill-mbstring": "~1.0",
2828
"symfony/filesystem": "~2.8|~3.0",
2929
"symfony/finder": "~2.8|~3.0",

0 commit comments

Comments
 (0)