8000 [FrameworkBundle] Use Bundle#getPath() to load config files · symfony/symfony@a0dc38e · GitHub
[go: up one dir, main page]

Skip to content

Commit a0dc38e

Browse files
committed
[FrameworkBundle] Use Bundle#getPath() to load config files
Replace breaking new instance by reflection
1 parent 44efeaa commit a0dc38e

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

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

Lines changed: 20 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 ($bundles as $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 ($bundles as $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 = new Definition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', array(realpath($file)));
@@ -990,6 +988,22 @@ 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+
private function getBundlePath($fqcn)
999+
{
1000+
$reflection = new \ReflectionClass($fqcn);
1001+
$getPathReflection = new \ReflectionMethod($fqcn, 'getPath');
1002+
$reflectionInstance = $reflection->newInstanceWithoutConstructor();
1003+
1004+
return $getPathReflection->invoke($reflectionInstance) ?: dirname($reflection->getFilename());
1005+
}
1006+
9931007
/**
9941008
* Returns the base path for the XSD files.
9951009
*

0 commit comments

Comments
 (0)
0