11
11
12
12
namespace Symfony \Bundle \FrameworkBundle \Kernel ;
13
13
14
+ use Symfony \Bundle \FrameworkBundle \FrameworkBundle ;
14
15
use Symfony \Component \Config \Loader \LoaderInterface ;
15
16
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
17
use Symfony \Component \DependencyInjection \Loader \Configurator \AbstractConfigurator ;
@@ -48,7 +49,7 @@ trait MicroKernelTrait
48
49
*/
49
50
private function configureContainer (ContainerConfigurator $ container , LoaderInterface $ loader , ContainerBuilder $ builder ): void
50
51
{
51
- $ configDir = $ this ->getConfigDir ();
52
+ $ configDir = preg_replace ( ' {/config$} ' , ' /{config} ' , $ this ->getConfigDir () );
52
53
53
54
$ container ->import ($ configDir .'/{packages}/*.{php,yaml} ' );
54
55
$ container ->import ($ configDir .'/{packages}/ ' .$ this ->environment .'/*.{php,yaml} ' );
@@ -73,7 +74,7 @@ private function configureContainer(ContainerConfigurator $container, LoaderInte
73
74
*/
74
75
private function configureRoutes (RoutingConfigurator $ routes ): void
75
76
{
76
- $ configDir = $ this ->getConfigDir ();
77
+ $ configDir = preg_replace ( ' {/config$} ' , ' /{config} ' , $ this ->getConfigDir () );
77
78
78
79
$ routes ->import ($ configDir .'/{routes}/ ' .$ this ->environment .'/*.{php,yaml} ' );
79
80
$ routes ->import ($ configDir .'/{routes}/*.{php,yaml} ' );
@@ -84,7 +85,7 @@ private function configureRoutes(RoutingConfigurator $routes): void
84
85
$ routes ->import ($ configDir .'/{routes}.php ' );
85
86
}
86
87
87
- if (false !== ( $ fileName = (new \ReflectionObject ($ this ))->getFileName () )) {
88
+ if ($ fileName = (new \ReflectionObject ($ this ))->getFileName ()) {
88
89
$ routes ->import ($ fileName , 'attribute ' );
89
90
}
90
91
}
@@ -130,7 +131,13 @@ public function getLogDir(): string
130
131
131
132
public function registerBundles (): iterable
132
133
{
133
- $ contents = require $ this ->getBundlesPath ();
134
+ if (!is_file ($ bundlesPath = $ this ->getBundlesPath ())) {
135
+ yield new FrameworkBundle ();
136
+
137
+ return ;
138
+ }
139
+
140
+ $ contents = require $ bundlesPath ;
134
141
foreach ($ contents as $ class => $ envs ) {
135
142
if ($ envs [$ this ->environment ] ?? $ envs ['all ' ] ?? false ) {
136
143
yield new $ class ();
@@ -216,6 +223,8 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection
216
223
$ route ->setDefault ('_controller ' , ['kernel ' , $ controller [1 ]]);
217
224
} elseif ($ controller instanceof \Closure && $ this === ($ r = new \ReflectionFunction ($ controller ))->getClosureThis () && !$ r ->isAnonymous ()) {
218
225
$ route ->setDefault ('_controller ' , ['kernel ' , $ r ->name ]);
226
+ } elseif ($ this ::class === $ controller && method_exists ($ this , '__invoke ' )) {
227
+ $ route ->setDefault ('_controller ' , 'kernel ' );
219
228
}
220
229
}
221
230
0 commit comments