@@ -79,7 +79,12 @@ file and make the needed changes.
79
79
80
80
In this example, the ``ApiKernel `` will load less bundles than the default
81
81
Kernel. Be sure to also change the location of the cache, logs and configuration
82
- files so they don't collide with the files from ``src/Kernel.php ``::
82
+ files so they don't collide with the files from ``src/Kernel.php ``.
83
+ We need to ``use MicroKernelTrait ``;
84
+ Because this Trait implement the method => ``registerContainerConfiguration `` at our place
85
+ However, since we use this Trait, we have to declare the ``configureRoutes `` method also
86
+
87
+ :
83
88
84
89
// src/ApiKernel.php
85
90
use Symfony\C omponent\C onfig\L oader\L oaderInterface;
@@ -88,11 +93,12 @@ files so they don't collide with the files from ``src/Kernel.php``::
88
93
89
94
class ApiKernel extends Kernel
90
95
{
91
- // ...
96
+ use MicroKernelTrait;
92
97
93
98
public function registerBundles()
94
99
{
95
- // load only the bundles strictly needed for the API...
100
+ $contents = require $this->getProjectDir().'/config/api_bundles.php';
101
+ // ...
96
102
}
97
103
98
104
public function getCacheDir()
@@ -107,16 +113,19 @@ files so they don't collide with the files from ``src/Kernel.php``::
107
113
108
114
public function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
109
115
{
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
- }
116
+ $container->addResource(new FileResource($this->getProjectDir().'/config/api_bundles.php'));
117
+ $container->setParameter('container.dumper.inline_factories', true);
118
+ $confDir = $this->getProjectDir().'/config/api';
119
+
120
+ $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
121
+ $loader->load($confDir.'/{packages}/'.$this->environment.'/ *'.self::CONFIG_EXTS, 'glob');
122
+ $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
123
+ $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
116
124
}
117
125
118
126
protected function configureRoutes(RouteCollectionBuilder $routes): void
119
127
{
128
+ $confDir = $this->getProjectDir().'/config/api';
120
129
// load only the config routes strictly needed for the API
121
130
}
122
131
}
0 commit comments