Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a689807

Browse files
[FrameworkBundle] Added flex-compatible default implementations for MicroKernelTrait::registerBundles() and getProjectDir()
1 parent 65a9888 commit a689807

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Marked `MicroKernelTrait::configureRoutes()` as `@internal` and `@final`.
88
* Deprecated not overriding `MicroKernelTrait::configureRouting()`.
99
* Added a new `mailer.message_bus` option to configure or disable the message bus to use to send mails.
10+
* Added flex-compatible default implementations for `MicroKernelTrait::registerBundles()` and `getProjectDir()`
1011

1112
5.0.0
1213
-----

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ protected function configureRouting(RoutingConfigurator $routes): void
7272
*/
7373
abstract protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader);
7474

75+
/**
76+
* {@inheritdoc}
77+
*/
78+
public function getProjectDir(): string
79+
{
80+
return \dirname((new \ReflectionObject($this))->getFileName(), 2);
81+
}
82+
83+
/**
84+
* {@inheritdoc}
85+
*/
86+
public function registerBundles(): iterable
87+
{
88+
$contents = require $this->getProjectDir().'/config/bundles.php';
89+
foreach ($contents as $class => $envs) {
90+
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
91+
yield new $class();
92+
}
93+
}
94+
}
95+
7596
/**
7697
* {@inheritdoc}
7798
*/
@@ -100,8 +121,8 @@ public function registerContainerConfiguration(LoaderInterface $loader)
100121
}
101122

102123
$this->configureContainer($container, $loader);
103-
104124
$container->addObjectResource($this);
125+
$container->fileExists($this->getProjectDir().'/config/bundles.php');
105126
});
106127
}
107128

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ public function dump(array $options = [])
151151
$this->namespace = $options['namespace'];
152152
$this->asFiles = $options['as_files'];
153153
$this->hotPathTag = $options['hot_path_tag'];
154-
$this->inlineFactories = $this->asFiles && $options['inline_factories_parameter'] && $this->container->hasParameter($options['inline_factories_parameter']) && $this->container->getParameter($options['inline_factories_parameter']);
155-
$this->inlineRequires = $options['inline_class_loader_parameter'] && $this->container->hasParameter($options['inline_class_loader_parameter']) && $this->container->getParameter($options['inline_class_loader_parameter']);
154+
$this->inlineFactories = $this->asFiles && $options['inline_factories_parameter'] && (!$this->container->hasParameter($options['inline_factories_parameter']) || $this->container->getParameter($options['inline_factories_parameter']));
155+
$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);
156156
$this->serviceLocatorTag = $options['service_locator_tag'];
157157

158158
if (0 !== strpos($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) {

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function testDumpAsFiles()
227227
->addError('No-no-no-no');
228228
$container->compile();
229229
$dumper = new PhpDumper($container);
230-
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot']), true);
230+
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]), true);
231231
if ('\\' === \DIRECTORY_SEPARATOR) {
232232
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo.php', '/Fixtures/includes/foo.php', $dump);
233233
}
@@ -297,7 +297,7 @@ public function testNonSharedLazyDumpAsFiles()
297297
->setLazy(true);
298298
$container->compile();
299299
$dumper = new PhpDumper($container);
300-
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__]), true);
300+
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]), true);
301301

302302
if ('\\' === \DIRECTORY_SEPARATOR) {
303303
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo_lazy.php', '/Fixtures/includes/foo_lazy.php', $dump);
@@ -478,7 +478,7 @@ public function testEnvParameter()
478478
$container->compile();
479479
$dumper = new PhpDumper($container);
480480

481-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services26.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_EnvParameters', 'file' => self::$fixturesPath.'/php/services26.php']));
481+
$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]));
482482

483483
require self::$fixturesPath.'/php/services26.php';
484484
$container = new \Symfony_DI_PhpDumper_Test_EnvParameters();
@@ -944,7 +944,7 @@ public function testArrayParameters()
944944

945945
$dumper = new PhpDumper($container);
946946

947-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php'])));
947+
$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])));
948948
}
949949

950950
public function testExpressionReferencingPrivateService()

0 commit comments

Comments
 (0)