8000 Merge branch '2.8' into 3.1 · symfony/symfony@8f82bf7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f82bf7

Browse files
committed
Merge branch '2.8' into 3.1
* 2.8: Fix serializer/translations/validator resources loading for bundles overriding getPath()
2 parents 1563b42 + 829b6bd commit 8f82bf7

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

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.
< F438 /td>
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
@@ -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' 10000 ; => 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',

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

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
@@ -219,6 +219,7 @@ private function createContainer()
219219
'kernel.charset' => 'UTF-8',
220220
'kernel.debug' => false,
221221
'kernel.bundles' => array('TwigBundle' => 'Symfony\\Bundle\\TwigBundle\\TwigBundle'),
222+
'kernel.bundles_metadata' => array('TwigBundle' => array('namespace' => 'Symfony\\Bundle\\TwigBundle', 'parent' => null, 'path' => realpath(__DIR__.'/../..'))),
222223
)));
223224

224225
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.8|~3.0",
2121
"symfony/twig-bridge": "~2.8|~3.0",
2222
"symfony/http-foundation": "~2.8|~3.0",
23-
"symfony/http-kernel": "~2.8|~3.0",
23+
"symfony/http-kernel": "~2.8.16|~3.1.9|^3.2.2",
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
@@ -498,8 +498,15 @@ protected function initializeContainer()
498498
protected function getKernelParameters()
499499
{
500500
$bundles = array();
501+
$bundlesMetadata = array();
502+
501503
foreach ($this->bundles as $name => $bundle) {
502504
$bundles[$name] = get_class($bundle);
505+
$bundlesMetadata[$name] = array(
506+
'parent' => $bundle->getParent(),
507+
'path' => $bundle->getPath(),
508+
'namespace' => $bundle->getNamespace(),
509+
);
503510
}
504511

505512
return array_merge(
@@ -511,6 +518,7 @@ protected function getKernelParameters()
511518
'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(),
512519
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
513520
'kernel.bundles' => $bundles,
521+
'kernel.bundles_metadata' => $bundlesMetadata,
514522
'kernel.charset' => $this->getCharset(),
515523
'kernel.container_class' => $this->getContainerClass(),
516524
),

0 commit comments

Comments
 (0)
0