From a68980738798233d257fa46875f32827f4537254 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 7 Dec 2019 14:19:06 +0100 Subject: [PATCH] [FrameworkBundle] Added flex-compatible default implementations for `MicroKernelTrait::registerBundles()` and `getProjectDir()` --- .../Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../Kernel/MicroKernelTrait.php | 23 ++++++++++++++++++- .../DependencyInjection/Dumper/PhpDumper.php | 4 ++-- .../Tests/Dumper/PhpDumperTest.php | 8 +++---- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index b2d148817c..44107bcd6c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -7,6 +7,7 @@ CHANGELOG * Marked `MicroKernelTrait::configureRoutes()` as `@internal` and `@final`. * Deprecated not overriding `MicroKernelTrait::configureRouting()`. * Added a new `mailer.message_bus` option to configure or disable the message bus to use to send mails. + * Added flex-compatible default implementations for `MicroKernelTrait::registerBundles()` and `getProjectDir()` 5.0.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php index df9e801bbc..f462fb6ace 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php @@ -72,6 +72,27 @@ trait MicroKernelTrait */ abstract protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader); + /** + * {@inheritdoc} + */ + public function getProjectDir(): string + { + return \dirname((new \ReflectionObject($this))->getFileName(), 2); + } + + /** + * {@inheritdoc} + */ + public function registerBundles(): iterable + { + $contents = require $this->getProjectDir().'/config/bundles.php'; + foreach ($contents as $class => $envs) { + if ($envs[$this->environment] ?? $envs['all'] ?? false) { + yield new $class(); + } + } + } + /** * {@inheritdoc} */ @@ -100,8 +121,8 @@ trait MicroKernelTrait } $this->configureContainer($container, $loader); - $container->addObjectResource($this); + $container->fileExists($this->getProjectDir().'/config/bundles.php'); }); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index b0dd26912b..315f79dc15 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -151,8 +151,8 @@ class PhpDumper extends Dumper $this->namespace = $options['namespace']; $this->asFiles = $options['as_files']; $this->hotPathTag = $options['hot_path_tag']; - $this->inlineFactories = $this->asFiles && $options['inline_factories_parameter'] && $this->container->hasParameter($options['inline_factories_parameter']) && $this->container->getParameter($options['inline_factories_parameter']); - $this->inlineRequires = $options['inline_class_loader_parameter'] && $this->container->hasParameter($options['inline_class_loader_parameter']) && $this->container->getParameter($options['inline_class_loader_parameter']); + $this->inlineFactories = $this->asFiles && $options['inline_factories_parameter'] && (!$this->container->hasParameter($options['inline_factories_parameter']) || $this->container->getParameter($options['inline_factories_parameter'])); + $this->inlineRequires = $options['inline_class_loader_parameter'] && ($this->container->hasParameter($options['inline_class_loader_parameter']) ? $this->container->getParameter($options['inline_class_loader_parameter']) : \PHP_VERSION_ID < 70400); $this->serviceLocatorTag = $options['service_locator_tag']; if (0 !== strpos($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 681c7ef68d..17f67ed099 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -227,7 +227,7 @@ class PhpDumperTest extends TestCase ->addError('No-no-no-no'); $container->compile(); $dumper = new PhpDumper($container); - $dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot']), true); + $dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]), true); if ('\\' === \DIRECTORY_SEPARATOR) { $dump = str_replace('\\\\Fixtures\\\\includes\\\\foo.php', '/Fixtures/includes/foo.php', $dump); } @@ -297,7 +297,7 @@ class PhpDumperTest extends TestCase ->setLazy(true); $container->compile(); $dumper = new PhpDumper($container); - $dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__]), true); + $dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]), true); if ('\\' === \DIRECTORY_SEPARATOR) { $dump = str_replace('\\\\Fixtures\\\\includes\\\\foo_lazy.php', '/Fixtures/includes/foo_lazy.php', $dump); @@ -478,7 +478,7 @@ class PhpDumperTest extends TestCase $container->compile(); $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services26.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_EnvParameters', 'file' => self::$fixturesPath.'/php/services26.php'])); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services26.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_EnvParameters', 'file' => self::$fixturesPath.'/php/services26.php', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false])); require self::$fixturesPath.'/php/services26.php'; $container = new \Symfony_DI_PhpDumper_Test_EnvParameters(); @@ -944,7 +944,7 @@ class PhpDumperTest extends TestCase $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php']))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]))); } public function testExpressionReferencingPrivateService()