@@ -88,31 +88,50 @@ files so they don't collide with the files from ``src/Kernel.php``::
88
88
89
89
class ApiKernel extends Kernel
90
90
{
91
- // ...
91
+ use MicroKernelTrait;
92
92
93
93
public function registerBundles()
94
94
{
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__);
96
107
}
97
108
98
- public function getCacheDir()
109
+ public function getCacheDir(): string
99
110
{
100
- return dirname(__DIR__ ).'/var/cache/api/'.$this->getEnvironment();
111
+ return $this->getProjectDir( ).'/var/cache/api/'.$this->getEnvironment();
101
112
}
102
113
103
- public function getLogDir()
114
+ public function getLogDir(): string
104
115
{
105
- return dirname(__DIR__ ).'/var/log/api';
116
+ return $this->getProjectDir( ).'/var/log/api';
106
117
}
107
118
108
119
public function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
109
120
{
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
116
135
}
117
136
}
118
137
0 commit comments