Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit be882c4

Browse filesBrowse files
committed
Merge branch '3.1' into 3.2
* 3.1: Fix serializer/translations/validator resources loading for bundles overriding getPath()
2 parents 142afa3 + 8f82bf7 commit be882c4
Copy full SHA for be882c4

File tree

Expand file treeCollapse file tree

10 files changed

+73
-22
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+73
-22
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+7-13Lines 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));

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

Copy file name to clipboardExpand all lines: 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

Copy file name to clipboardExpand all lines: 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+30-1Lines 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',

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+1-1Lines 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",

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
+5-6Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ private function createContainer()
245245
'kernel.charset' => 'UTF-8',
246246
'kernel.debug' => false,
247247
'kernel.bundles' => array('TwigBundle' => 'Symfony\\Bundle\\TwigBundle\\TwigBundle'),
248+
'kernel.bundles_metadata' => array('TwigBundle' => array('namespace' => 'Symfony\\Bundle\\TwigBundle', 'parent' => null, 'path' => realpath(__DIR__.'/../..'))),
248249
)));
249250

250251
return $container;

‎src/Symfony/Bundle/TwigBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/config": "~3.2",
2121
"symfony/twig-bridge": "^3.2.1",
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Kernel.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,15 @@ protected function initializeContainer()
505505
protected function getKernelParameters()
506506
{
507507
$bundles = array();
508+
$bundlesMetadata = array();
509+
508510
foreach ($this->bundles as $name => $bundle) {
509511
$bundles[$name] = get_class($bundle);
512+
$bundlesMetadata[$name] = array(
513+
'parent' => $bundle->getParent(),
514+
'path' => $bundle->getPath(),
515+
'namespace' => $bundle->getNamespace(),
516+
);
510517
}
511518

512519
return array_merge(
@@ -518,6 +525,7 @@ protected function getKernelParameters()
518525
'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(),
519526
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
520527
'kernel.bundles' => $bundles,
528+
'kernel.bundles_metadata' => $bundlesMetadata,
521529
'kernel.charset' => $this->getCharset(),
522530
'kernel.container_class' => $this->getContainerClass(),
523531
),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.