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

Commitc09e7ad

Browse files
committed
[FrameworkBundle] Use Bundle#getPath() to load config files
Replace breaking new instance by reflectionPrevent unsupported method call for php < 5.4
1 parent44efeaa commitc09e7ad

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,8 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
694694
}
695695
$rootDir =$container->getParameter('kernel.root_dir');
696696
foreach ($container->getParameter('kernel.bundles')as$bundle =>$class) {
697-
$reflection =new \ReflectionClass($class);
698-
if (is_dir($dir =dirname($reflection->getFileName()).'/Resources/translations')) {
697+
$dirname =$this->getBundlePath($class);
698+
if (is_dir($dir =$dirname.'/Resources/translations')) {
699699
$dirs[] =$dir;
700700
}
701701
if (is_dir($dir =$rootDir.sprintf('/Resources/%s/translations',$bundle))) {
@@ -808,8 +808,7 @@ private function getValidatorMappingFiles(ContainerBuilder $container)
808808

809809
$bundles =$container->getParameter('kernel.bundles');
810810
foreach ($bundlesas$bundle) {
811-
$reflection =new \ReflectionClass($bundle);
812-
$dirname =dirname($reflection->getFileName());
811+
$dirname =$this->getBundlePath($bundle);
813812

814813
if (is_file($file =$dirname.'/Resources/config/validation.xml')) {
815814
$files[0][] =realpath($file);
@@ -923,8 +922,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
923922

924923
$bundles =$container->getParameter('kernel.bundles');
925924
foreach ($bundlesas$bundle) {
926-
$reflection =new \ReflectionClass($bundle);
927-
$dirname =dirname($reflection->getFileName());
925+
$dirname =$this->getBundlePath($bundle);
928926

929927
if (is_file($file =$dirname.'/Resources/config/serialization.xml')) {
930928
$definition =newDefinition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader',array(realpath($file)));
@@ -990,6 +988,28 @@ private function getKernelRootHash(ContainerBuilder $container)
990988
return$this->kernelRootHash;
991989
}
992990

991+
/**
992+
* Gets the path of a given bundle using Bundle#getPath() when available.
993+
*
994+
* @param string $fqcn The bundle FQCN
995+
*
996+
* @return string
997+
*/
998+
privatefunctiongetBundlePath($fqcn)
999+
{
1000+
$reflection =new \ReflectionClass($fqcn);
1001+
$defaultPath =dirname($reflection->getFilename());
1002+
1003+
if (PHP_VERSION_ID <50400) {
1004+
return$defaultPath;
1005+
}
1006+
1007+
$reflectionInstance =$reflection->newInstanceWithoutConstructor();
1008+
$reflectedPathGetter =new \ReflectionMethod($fqcn,'getPath');
1009+
1010+
return$reflectedPathGetter->invoke($reflectionInstance) ?:$defaultPath;
1011+
}
1012+
9931013
/**
9941014
* Returns the base path for the XSD files.
9951015
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp