@@ -82,9 +82,10 @@ Kernel. Be sure to also change the location of the cache, logs and configuration
8282files so they don't collide with the files from ``src/Kernel.php ``::
8383
8484 // src/ApiKernel.php
85- use Symfony\Component\Config\Loader\LoaderInterface;
86- use Symfony\Component\DependencyInjection\ContainerBuilder;
87- use Symfony\Component\HttpKernel\Kernel;
85+ use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
86+ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
87+ use Symfony\Component\HttpKernel\Kernel as BaseKernel;
88+ use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
8889
8990 class ApiKernel extends Kernel
9091 {
@@ -101,36 +102,33 @@ files so they don't collide with the files from ``src/Kernel.php``::
101102 }
102103 }
103104
104- public function getProjectDir(): string
105- {
106- return \dirname(__DIR__);
107- }
108-
109105 public function getCacheDir(): string
110106 {
111- return $this->getProjectDir().'/var/cache/api/'.$this->getEnvironment() ;
107+ return $this->getProjectDir().'/var/cache/api/'.$this->environment ;
112108 }
113109
114110 public function getLogDir(): string
115111 {
116112 return $this->getProjectDir().'/var/log/api';
117113 }
118114
119- public function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
115+ protected function configureContainer(ContainerConfigurator $container): void
120116 {
121- $container->addResource(new FileResource($this->getProjectDir().'/config/api_bundles.php'));
122- $container->setParameter('container.dumper.inline_factories', true);
123- $confDir = $this->getProjectDir().'/config/api';
124-
125- $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
126- $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
127- $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
128- $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
117+ $container->import('../config/api/{packages}/*.yaml');
118+ $container->import('../config/api/{packages}/'.$this->environment.'/*.yaml');
119+
120+ if (is_file(\dirname(__DIR__).'/config/api/services.yaml')) {
121+ $container->import('../config/api/services.yaml');
122+ $container->import('../config/api/{services}_'.$this->environment.'.yaml');
123+ } else {
124+ $container->import('../config/api/{services}.php');
125+ }
129126 }
130127
131- protected function configureRoutes(RouteCollectionBuilder $routes): void
128+ protected function configureRoutes(RoutingConfigurator $routes): void
132129 {
133- $confDir = $this->getProjectDir().'/config/api';
130+ $routes->import('../config/api/{routes}/'.$this->environment.'/*.yaml');
131+ $routes->import('../config/api/{routes}/*.yaml');
134132 // ... load only the config routes strictly needed for the API
135133 }
136134 }
0 commit comments