@@ -88,31 +88,50 @@ files so they don't collide with the files from ``src/Kernel.php``::
8888
8989 class ApiKernel extends Kernel
9090 {
91- // ...
91+ use MicroKernelTrait;
9292
9393 public function registerBundles()
9494 {
95- // load only the bundles strictly needed for the API...
95+ // load only the bundles strictly needed for the API
96+ $contents = require $this->getProjectDir().'/config/api_bundles.php';
97+ foreach ($contents as $class => $envs) {
98+ if ($envs[$this->environment] ?? $envs['all'] ?? false) {
99+ yield new $class();
100+ }
101+ }
102+ }
103+
104+ public function getProjectDir(): string
105+ {
106+ return \dirname(__DIR__);
96107 }
97108
98- public function getCacheDir()
109+ public function getCacheDir(): string
99110 {
100- return dirname(__DIR__ ).'/var/cache/api/'.$this->getEnvironment();
111+ return $this->getProjectDir( ).'/var/cache/api/'.$this->getEnvironment();
101112 }
102113
103- public function getLogDir()
114+ public function getLogDir(): string
104115 {
105- return dirname(__DIR__ ).'/var/log/api';
116+ return $this->getProjectDir( ).'/var/log/api';
106117 }
107118
108119 public function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
109120 {
110- // load only the config files strictly needed for the API
111- $confDir = $this->getProjectDir().'/config';
112- $loader->load($confDir.'/api/*'.self::CONFIG_EXTS, 'glob');
113- if (is_dir($confDir.'/api/'.$this->environment)) {
114- $loader->load($confDir.'/api/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
115- }
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');
129+ }
130+
131+ protected function configureRoutes(RouteCollectionBuilder $routes): void
132+ {
133+ $confDir = $this->getProjectDir().'/config/api';
134+ // ... load only the config routes strictly needed for the API
116135 }
117136 }
118137
0 commit comments