diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 13966eb99dbd4..b6b7a450e08ff 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -692,12 +692,11 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder $dirs[] = dirname(dirname($r->getFileName())).'/Resources/translations'; } $rootDir = $container->getParameter('kernel.root_dir'); - foreach ($container->getParameter('kernel.bundles') as $bundle => $class) { - $reflection = new \ReflectionClass($class); - if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) { + foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) { + if (is_dir($dir = $bundle['path'].'/Resources/translations')) { $dirs[] = $dir; } - if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) { + if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) { $dirs[] = $dir; } } @@ -809,11 +808,8 @@ private function getValidatorMappingFiles(ContainerBuilder $container) $container->addResource(new FileResource($files[0][0])); } - $bundles = $container->getParameter('kernel.bundles'); - foreach ($bundles as $bundle) { - $reflection = new \ReflectionClass($bundle); - $dirname = dirname($reflection->getFileName()); - + foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) { + $dirname = $bundle['path']; if (is_file($file = $dirname.'/Resources/config/validation.xml')) { $files[0][] = $file; $container->addResource(new FileResource($file)); @@ -924,10 +920,8 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder $serializerLoaders[] = $annotationLoader; } - $bundles = $container->getParameter('kernel.bundles'); - foreach ($bundles as $bundle) { - $reflection = new \ReflectionClass($bundle); - $dirname = dirname($reflection->getFileName()); + foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) { + $dirname = $bundle['path']; if (is_file($file = $dirname.'/Resources/config/serialization.xml')) { $definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', array($file)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/CustomPathBundle/Resources/config/validation.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/CustomPathBundle/Resources/config/validation.xml new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/CustomPathBundle/Resources/config/validation.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/CustomPathBundle/Resources/config/validation.yml new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/CustomPathBundle/src/CustomPathBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/CustomPathBundle/src/CustomPathBundle.php new file mode 100644 index 0000000000000..31cec239d894f --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/CustomPathBundle/src/CustomPathBundle.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests; + +class CustomPathBundle extends \Symfony\Component\HttpKernel\Bundle\Bundle +{ + public function getPath() + { + return __DIR__.'/..'; + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 922d6f95738f6..9736cf17c3231 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -342,7 +342,8 @@ public function testValidationPaths() require_once __DIR__.'/Fixtures/TestBundle/TestBundle.php'; $container = $this->createContainerFromFile('validation_annotations', array( - 'kernel.bundles' => array('TestBundle' => 'Symfony\Bundle\FrameworkBundle\Tests\TestBundle'), + 'kernel.bundles' => array('TestBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle'), + 'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/TestBundle')), )); $calls = $container->getDefinition('validator.builder')->getMethodCalls(); @@ -370,6 +371,33 @@ public function testValidationPaths() $this->assertStringEndsWith('TestBundle/Resources/config/validation.yml', $yamlMappings[0]); } + public function testValidationPathsUsingCustomBundlePath() + { + require_once __DIR__.'/Fixtures/CustomPathBundle/src/CustomPathBundle.php'; + + $container = $this->createContainerFromFile('validation_annotations', array( + 'kernel.bundles' => array('CustomPathBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\CustomPathBundle'), + 'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'parent' => null, 'path' => __DIR__.'/Fixtures/CustomPathBundle')), + )); + + $calls = $container->getDefinition('validator.builder')->getMethodCalls(); + $xmlMappings = $calls[3][1][0]; + $this->assertCount(2, $xmlMappings); + + try { + // Testing symfony/symfony + $this->assertStringEndsWith('Component'.DIRECTORY_SEPARATOR.'Form/Resources/config/validation.xml', $xmlMappings[0]); + } catch (\Exception $e) { + // Testing symfony/framework-bundle with deps=high + $this->assertStringEndsWith('symfony'.DIRECTORY_SEPARATOR.'form/Resources/config/validation.xml', $xmlMappings[0]); + } + $this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.xml', $xmlMappings[1]); + + $yamlMappings = $calls[4][1][0]; + $this->assertCount(1, $yamlMappings); + $this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.yml', $yamlMappings[0]); + } + public function testValidationNoStaticMethod() { $container = $this->createContainerFromFile('validation_no_static_method'); @@ -472,6 +500,7 @@ protected function createContainer(array $data = array()) { return new ContainerBuilder(new ParameterBag(array_merge(array( 'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'), + 'kernel.bundles_metadata' => array('FrameworkBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..', 'parent' => null)), 'kernel.cache_dir' => __DIR__, 'kernel.debug' => false, 'kernel.environment' => 'test', diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index ead3235670602..63c43e003506b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -23,7 +23,7 @@ "symfony/event-dispatcher": "~2.5", "symfony/finder": "~2.0,>=2.0.5", "symfony/http-foundation": "~2.7", - "symfony/http-kernel": "~2.7.15|~2.8.8", + "symfony/http-kernel": "~2.7.23|~2.8.16", "symfony/filesystem": "~2.3", "symfony/routing": "~2.6,>2.6.4", "symfony/security-core": "~2.6.13|~2.7.9|~2.8", diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 5eb163c8869bb..e9f55f758da21 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -89,14 +89,13 @@ public function load(array $configs, ContainerBuilder $container) } // register bundles as Twig namespaces - foreach ($container->getParameter('kernel.bundles') as $bundle => $class) { - if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views')) { - $this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle); + foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) { + if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views')) { + $this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $name); } - $reflection = new \ReflectionClass($class); - if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/views')) { - $this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle); + if (is_dir($dir = $bundle['path'].'/Resources/views')) { + $this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $name); } } diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index fcfa38a4bb1a8..ab4d649428a58 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -255,6 +255,7 @@ private function createContainer() 'kernel.charset' => 'UTF-8', 'kernel.debug' => false, 'kernel.bundles' => array('TwigBundle' => 'Symfony\\Bundle\\TwigBundle\\TwigBundle'), + 'kernel.bundles_metadata' => array('TwigBundle' => array('namespace' => 'Symfony\\Bundle\\TwigBundle', 'parent' => null, 'path' => realpath(__DIR__.'/../..'))), ))); return $container; diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 8c4947db65f27..861b45d56178d 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -21,7 +21,7 @@ "symfony/twig-bridge": "~2.7", "twig/twig": "~1.28|~2.0", "symfony/http-foundation": "~2.5", - "symfony/http-kernel": "~2.7" + "symfony/http-kernel": "~2.7.23|~2.8.16" }, "require-dev": { "symfony/stopwatch": "~2.2", diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 81f7b2a6140ae..d4e79f35b6510 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -531,8 +531,15 @@ protected function initializeContainer() protected function getKernelParameters() { $bundles = array(); + $bundlesMetadata = array(); + foreach ($this->bundles as $name => $bundle) { $bundles[$name] = get_class($bundle); + $bundlesMetadata[$name] = array( + 'parent' => $bundle->getParent(), + 'path' => $bundle->getPath(), + 'namespace' => $bundle->getNamespace(), + ); } return array_merge( @@ -544,6 +551,7 @@ protected function getKernelParameters() 'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(), 'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(), 'kernel.bundles' => $bundles, + 'kernel.bundles_metadata' => $bundlesMetadata, 'kernel.charset' => $this->getCharset(), 'kernel.container_class' => $this->getContainerClass(), ),