22
33declare (strict_types=1 );
44
5- use Symfony \Bundle \FrameworkBundle \Kernel \MicroKernelTrait ;
65use Symfony \Component \Config \Loader \LoaderInterface ;
76use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
87use Symfony \Component \DependencyInjection \ContainerBuilder ;
98use Symfony \Component \HttpFoundation \Response ;
109use Symfony \Component \HttpKernel \Kernel ;
11- use Symfony \Component \Routing \RouteCollectionBuilder ;
10+ use Symfony \Component \Routing \Loader \Configurator \RoutingConfigurator ;
11+ use Symfony \Component \Routing \Loader \PhpFileLoader as RoutingPhpFileLoader ;
12+ use Symfony \Component \Routing \Route ;
13+ use Symfony \Component \Routing \RouteCollection ;
1214
1315class AppKernel extends Kernel
1416{
15- use MicroKernelTrait;
16-
1717 /**
1818 * @var string
1919 */
@@ -22,7 +22,7 @@ class AppKernel extends Kernel
2222 /**
2323 * {@inheritdoc}
2424 */
25- public function registerBundles ()
25+ public function registerBundles (): iterable
2626 {
2727 $ bundles = [
2828 new \Symfony \Bundle \FrameworkBundle \FrameworkBundle (),
@@ -37,37 +37,52 @@ public function registerBundles()
3737 return $ bundles ;
3838 }
3939
40- /**
41- * {@inheritdoc}
42- */
43- protected function configureContainer (ContainerBuilder $ container , LoaderInterface $ loader ): void
40+ public function registerContainerConfiguration (LoaderInterface $ loader )
4441 {
45- $ loader ->load (__DIR__ .'/config/config_ ' .$ this ->getEnvironment ().'.yml ' );
46- if ($ this ->isDebug ()) {
47- $ loader ->load (__DIR__ .'/config/config_debug.yml ' );
48- }
42+ $ loader ->load (function (ContainerBuilder $ container ) use ($ loader ) {
43+ $ container ->loadFromExtension ('framework ' , [
44+ 'router ' => [
45+ 'resource ' => 'kernel::loadRoutes ' ,
46+ 'type ' => 'service ' ,
47+ 'utf8 ' => true ,
48+ ],
49+ ]);
50+
51+ $ container ->register ('kernel ' , static ::class)
52+ ->addTag ('routing.route_loader ' )
53+ ->setAutoconfigured (true )
54+ ->setSynthetic (true )
55+ ->setPublic (true )
56+ ;
57+
58+ $ loader ->load (__DIR__ .'/config/config_ ' .$ this ->getEnvironment ().'.yml ' );
59+ if ($ this ->isDebug ()) {
60+ $ loader ->load (__DIR__ .'/config/config_debug.yml ' );
61+ }
62+ });
4963 }
5064
51- /**
52- * {@inheritdoc}
53- */
54- protected function configureRoutes (RouteCollectionBuilder $ routes ): void
65+ public function loadRoutes (LoaderInterface $ loader ): RouteCollection
5566 {
56- $ routes ->import ('@WebProfilerBundle/Resources/config/routing/wdt.xml ' , '/_wdt ' );
57- $ routes ->import ('@WebProfilerBundle/Resources/config/routing/profiler.xml ' , '/_profiler ' );
58-
59- if (Kernel::MAJOR_VERSION < 4 || (Kernel::MAJOR_VERSION === 4 && Kernel::MINOR_VERSION === 0 )) {
60- $ routes ->add ('/ ' , 'kernel:indexAction ' );
61- } else {
62- // If 4.1+
63- $ routes ->add ('/ ' , 'kernel::indexAction ' );
64- }
67+ $ file = (new \ReflectionObject ($ this ))->getFileName ();
68+ /* @var RoutingPhpFileLoader $kernelLoader */
69+ $ kernelLoader = $ loader ->getResolver ()->resolve ($ file , 'php ' );
70+ $ kernelLoader ->setCurrentDir (\dirname ($ file ));
71+
72+ $ collection = new RouteCollection ();
73+ $ collection ->add ('/ ' , new Route ('/ ' , ['_controller ' => 'kernel::indexAction ' ]));
74+
75+ $ routes = new RoutingConfigurator ($ collection , $ kernelLoader , $ file , $ file );
76+ $ routes ->import ('@WebProfilerBundle/Resources/config/routing/wdt.xml ' )->prefix ('_wdt ' );
77+ $ routes ->import ('@WebProfilerBundle/Resources/config/routing/profiler.xml ' )->prefix ('_profiler ' );
78+
79+ return $ collection ;
6580 }
6681
6782 /**
6883 * {@inheritdoc}
6984 */
70- public function getCacheDir ()
85+ public function getCacheDir (): string
7186 {
7287 if (null === self ::$ cacheDir ) {
7388 self ::$ cacheDir = uniqid ('cache ' );
@@ -79,19 +94,11 @@ public function getCacheDir()
7994 /**
8095 * {@inheritdoc}
8196 */
82- public function getLogDir ()
97+ public function getLogDir (): string
8398 {
8499 return sys_get_temp_dir ().'/httplug-bundle/logs ' ;
85100 }
86101
87- /**
88- * {@inheritdoc}
89- */
90- protected function getContainerBaseClass ()
91- {
92- return '\PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer ' ;
93- }
94-
95102 public function indexAction ()
96103 {
97104 return new Response ();
0 commit comments