Skip to content

Commit 4235a36

Browse files
feature #34872 [FrameworkBundle] Added flex-compatible default implementations for MicroKernelTrait::registerBundles() and getProjectDir() (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [FrameworkBundle] Added flex-compatible default implementations for `MicroKernelTrait::registerBundles()` and `getProjectDir()` | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - I think it's safe now to migrate some flex-based defaults from the recipe to the bundle. No BC break here as all existing kernels already redefine this method. Commits ------- a689807387 [FrameworkBundle] Added flex-compatible default implementations for `MicroKernelTrait::registerBundles()` and `getProjectDir()`
2 parents dfa8edd + dd96795 commit 4235a36

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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
-----

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

0 commit comments

Comments
 (0)