Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitfc6afb3

Browse files
committed
Fix serializer/translations/validator resources loading for bundles overriding getPath()
1 parent6699928 commitfc6afb3

File tree

7 files changed

+66
-15
lines changed

7 files changed

+66
-15
lines changed

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,11 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
692692
$dirs[] =dirname(dirname($r->getFileName())).'/Resources/translations';
693693
}
694694
$rootDir =$container->getParameter('kernel.root_dir');
695-
foreach ($container->getParameter('kernel.bundles')as$bundle =>$class) {
696-
$reflection =new \ReflectionClass($class);
697-
if (is_dir($dir =dirname($reflection->getFileName()).'/Resources/translations')) {
695+
foreach ($container->getParameter('kernel.bundles_metadata')as$name =>$bundle) {
696+
if (is_dir($dir =$bundle['path'].'/Resources/translations')) {
698697
$dirs[] =$dir;
699698
}
700-
if (is_dir($dir =$rootDir.sprintf('/Resources/%s/translations',$bundle))) {
699+
if (is_dir($dir =$rootDir.sprintf('/Resources/%s/translations',$name))) {
701700
$dirs[] =$dir;
702701
}
703702
}
@@ -809,11 +808,8 @@ private function getValidatorMappingFiles(ContainerBuilder $container)
809808
$container->addResource(newFileResource($files[0][0]));
810809
}
811810

812-
$bundles =$container->getParameter('kernel.bundles');
813-
foreach ($bundlesas$bundle) {
814-
$reflection =new \ReflectionClass($bundle);
815-
$dirname =dirname($reflection->getFileName());
816-
811+
foreach ($container->getParameter('kernel.bundles_metadata')as$bundle) {
812+
$dirname =$bundle['path'];
817813
if (is_file($file =$dirname.'/Resources/config/validation.xml')) {
818814
$files[0][] =$file;
819815
$container->addResource(newFileResource($file));
@@ -924,10 +920,8 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
924920
$serializerLoaders[] =$annotationLoader;
925921
}
926922

927-
$bundles =$container->getParameter('kernel.bundles');
928-
foreach ($bundlesas$bundle) {
929-
$reflection =new \ReflectionClass($bundle);
930-
$dirname =dirname($reflection->getFileName());
923+
foreach ($container->getParameter('kernel.bundles_metadata')as$bundle) {
924+
$dirname =$bundle['path'];
931925

932926
if (is_file($file =$dirname.'/Resources/config/serialization.xml')) {
933927
$definition =newDefinition('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.
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+
namespaceSymfony\Bundle\FrameworkBundle\Tests;
13+
14+
class CustomPathBundleextends \Symfony\Component\HttpKernel\Bundle\Bundle
15+
{
16+
publicfunctiongetPath()
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
@@ -342,7 +342,8 @@ public function testValidationPaths()
342342
require_once__DIR__.'/Fixtures/TestBundle/TestBundle.php';
343343

344344
$container =$this->createContainerFromFile('validation_annotations',array(
345-
'kernel.bundles' =>array('TestBundle' =>'Symfony\Bundle\FrameworkBundle\Tests\TestBundle'),
345+
'kernel.bundles' =>array('TestBundle' =>'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle'),
346+
'kernel.bundles_metadata' =>array('TestBundle' =>array('namespace' =>'Symfony\\Bundle\\FrameworkBundle\\Tests','parent' =>null,'path' =>__DIR__.'/Fixtures/TestBundle')),
346347
));
347348

348349
$calls =$container->getDefinition('validator.builder')->getMethodCalls();
@@ -370,6 +371,33 @@ public function testValidationPaths()
370371
$this->assertStringEndsWith('TestBundle/Resources/config/validation.yml',$yamlMappings[0]);
371372
}
372373

374+
publicfunctiontestValidationPathsUsingCustomBundlePath()
375+
{
376+
require_once__DIR__.'/Fixtures/CustomPathBundle/src/CustomPathBundle.php';
377+
378+
$container =$this->createContainerFromFile('validation_annotations',array(
379+
'kernel.bundles' =>array('CustomPathBundle' =>'Symfony\\Bundle\\FrameworkBundle\\Tests\\CustomPathBundle'),
380+
'kernel.bundles_metadata' =>array('TestBundle' =>array('namespace' =>'Symfony\\Bundle\\FrameworkBundle\\Tests','parent' =>null,'path' =>__DIR__.'/Fixtures/CustomPathBundle')),
381+
));
382+
383+
$calls =$container->getDefinition('validator.builder')->getMethodCalls();
384+
$xmlMappings =$calls[3][1][0];
385+
$this->assertCount(2,$xmlMappings);
386+
387+
try {
388+
// Testing symfony/symfony
389+
$this->assertStringEndsWith('Component'.DIRECTORY_SEPARATOR.'Form/Resources/config/validation.xml',$xmlMappings[0]);
390+
}catch (\Exception$e) {
391+
// Testing symfony/framework-bundle with deps=high
392+
$this->assertStringEndsWith('symfony'.DIRECTORY_SEPARATOR.'form/Resources/config/validation.xml',$xmlMappings[0]);
393+
}
394+
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.xml',$xmlMappings[1]);
395+
396+
$yamlMappings =$calls[4][1][0];
397+
$this->assertCount(1,$yamlMappings);
398+
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.yml',$yamlMappings[0]);
399+
}
400+
373401
publicfunctiontestValidationNoStaticMethod()
374402
{
375403
$container =$this->createContainerFromFile('validation_no_static_method');
@@ -472,6 +500,7 @@ protected function createContainer(array $data = array())
472500
{
473501
returnnewContainerBuilder(newParameterBag(array_merge(array(
474502
'kernel.bundles' =>array('FrameworkBundle' =>'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'),
503+
'kernel.bundles_metadata' =>array('FrameworkBundle' =>array('namespace' =>'Symfony\\Bundle\\FrameworkBundle','path' =>__DIR__.'/../..','parent' =>null)),
475504
'kernel.cache_dir' =>__DIR__,
476505
'kernel.debug' =>false,
477506
'kernel.environment' =>'test',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/event-dispatcher":"~2.5",
2424
"symfony/finder":"~2.0,>=2.0.5",
2525
"symfony/http-foundation":"~2.7",
26-
"symfony/http-kernel":"~2.7.15|~2.8.8",
26+
"symfony/http-kernel":"~2.7.23|~2.8.16",
2727
"symfony/filesystem":"~2.3",
2828
"symfony/routing":"~2.6,>2.6.4",
2929
"symfony/security-core":"~2.6.13|~2.7.9|~2.8",

‎src/Symfony/Component/HttpKernel/Kernel.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,15 @@ protected function initializeContainer()
531531
protectedfunctiongetKernelParameters()
532532
{
533533
$bundles =array();
534+
$bundlesMetadata =array();
535+
534536
foreach ($this->bundlesas$name =>$bundle) {
535537
$bundles[$name] =get_class($bundle);
538+
$bundlesMetadata[$name] =array(
539+
'parent' =>$bundle->getParent(),
540+
'path' =>$bundle->getPath(),
541+
'namespace' =>$bundle->getNamespace(),
542+
);
536543
}
537544

538545
returnarray_merge(
@@ -544,6 +551,7 @@ protected function getKernelParameters()
544551
'kernel.cache_dir' =>realpath($this->getCacheDir()) ?:$this->getCacheDir(),
545552
'kernel.logs_dir' =>realpath($this->getLogDir()) ?:$this->getLogDir(),
546553
'kernel.bundles' =>$bundles,
554+
'kernel.bundles_metadata' =>$bundlesMetadata,
547555
'kernel.charset' =>$this->getCharset(),
548556
'kernel.container_class' =>$this->getContainerClass(),
549557
),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp