13
13
14
14
use Symfony \Component \Config \Loader \LoaderInterface ;
15
15
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
+ use Symfony \Component \DependencyInjection \Definition ;
17
+ use Symfony \Component \DependencyInjection \Loader \Configurator \AbstractConfigurator ;
16
18
use Symfony \Component \DependencyInjection \Loader \Configurator \ContainerConfigurator ;
17
- use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
19
+ use Symfony \Component \DependencyInjection \Loader \PhpFileLoader as ContainerPhpFileLoader ;
20
+ use Symfony \Component \DependencyInjection \Reference ;
18
21
use Symfony \Component \Routing \Loader \Configurator \RoutingConfigurator ;
22
+ use Symfony \Component \Routing \Loader \PhpFileLoader as RoutingPhpFileLoader ;
19
23
use Symfony \Component \Routing \RouteCollection ;
20
24
use Symfony \Component \Routing \RouteCollectionBuilder ;
21
25
@@ -93,6 +97,8 @@ public function registerContainerConfiguration(LoaderInterface $loader)
93
97
94
98
if (!$ container ->hasDefinition ('kernel ' )) {
95
99
$ container ->register ('kernel ' , static ::class)
100
+ ->addTag ('controller.service_arguments ' )
101
+ ->setAutoconfigured (true )
96
102
->setSynthetic (true )
97
103
->setPublic (true )
98
104
;
@@ -101,12 +107,9 @@ public function registerContainerConfiguration(LoaderInterface $loader)
101
107
$ kernelDefinition = $ container ->getDefinition ('kernel ' );
102
108
$ kernelDefinition ->addTag ('routing.route_loader ' );
103
109
104
- if ($ this instanceof EventSubscriberInterface) {
105
- $ kernelDefinition ->addTag ('kernel.event_subscriber ' );
106
- }
107
-
108
110
$ container ->addObjectResource ($ this );
109
111
$ container ->fileExists ($ this ->getProjectDir ().'/config/bundles.php ' );
112
+ $ container ->setParameter ('kernel.secret ' , '%env(APP_SECRET)% ' );
110
113
111
114
try {
112
115
$ this ->configureContainer ($ container , $ loader );
@@ -120,16 +123,27 @@ public function registerContainerConfiguration(LoaderInterface $loader)
120
123
}
121
124
}
122
125
126
+ // the user has opted into using the ContainerConfigurator
127
+ $ defaultDefinition = (new Definition ())->setAutowired (true )->setAutoconfigured (true );
128
+ /* @var ContainerPhpFileLoader $kernelLoader */
123
129
$ kernelLoader = $ loader ->getResolver ()->resolve ($ file );
124
130
$ kernelLoader ->setCurrentDir (\dirname ($ file ));
125
131
$ instanceof = &\Closure::bind (function &() { return $ this ->instanceof ; }, $ kernelLoader , $ kernelLoader )();
126
132
133
+ $ valuePreProcessor = AbstractConfigurator::$ valuePreProcessor ;
134
+ AbstractConfigurator::$ valuePreProcessor = function ($ value ) {
135
+ return $ this === $ value ? new Reference ('kernel ' ) : $ value ;
136
+ };
137
+
127
138
try {
128
- $ this ->configureContainer (new ContainerConfigurator ($ container , $ kernelLoader , $ instanceof , $ file , $ file ), $ loader );
139
+ $ this ->configureContainer (new ContainerConfigurator ($ container , $ kernelLoader , $ instanceof , $ file , $ file, $ defaultDefinition ), $ loader );
129
140
} finally {
130
141
$ instanceof = [];
131
142
$ kernelLoader ->registerAliasesForSinglyImplementedInterfaces ();
143
+ AbstractConfigurator::$ valuePreProcessor = $ valuePreProcessor ;
132
144
}
145
+
146
+ $ container ->setAlias (static ::class, 'kernel ' );
133
147
});
134
148
}
135
149
@@ -139,13 +153,22 @@ public function registerContainerConfiguration(LoaderInterface $loader)
139
153
public function loadRoutes (LoaderInterface $ loader )
140
154
{
141
155
$ file = (new \ReflectionObject ($ this ))->getFileName ();
156
+ /* @var RoutingPhpFileLoader $kernelLoader */
142
157
$ kernelLoader = $ loader ->getResolver ()->resolve ($ file );
143
158
$ kernelLoader ->setCurrentDir (\dirname ($ file ));
144
159
$ collection = new RouteCollection ();
145
160
146
161
try {
147
162
$ this ->configureRoutes (new RoutingConfigurator ($ collection , $ kernelLoader , $ file , $ file ));
148
163
164
+ foreach ($ collection as $ route ) {
165
+ $ controller = $ route ->getDefault ('_controller ' );
166
+
167
+ if (\is_array ($ controller ) && [0 , 1 ] === array_keys ($ controller ) && $ this === $ controller [0 ]) {
168
+ $ route ->setDefault ('_controller ' , ['kernel ' , $ controller [1 ]]);
169
+ }
170
+ }
171
+
149
172
return $ collection ;
150
173
} catch (\TypeError $ e ) {
151
174
if (0 !== strpos ($ e ->getMessage (), sprintf ('Argument 1 passed to %s::configureRoutes() must be an instance of %s, ' , static ::class, RouteCollectionBuilder::class))) {
0 commit comments