8000 Update multiple_kernels.rst · symfony/symfony-docs@d36e155 · GitHub
[go: up one dir, main page]

Skip to content

Commit d36e155

Browse files
authored
Update multiple_kernels.rst
1 parent aaeb899 commit d36e155

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

configuration/multiple_kernels.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ file and make the needed changes.
7979

8080
In this example, the ``ApiKernel`` will load less bundles than the default
8181
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+
:
8388

8489
// src/ApiKernel.php
8590
use Symfony\Component\Config\Loader\LoaderInterface;
@@ -88,11 +93,12 @@ files so they don't collide with the files from ``src/Kernel.php``::
8893

8994
class ApiKernel extends Kernel
9095
{
91-
// ...
96+
use MicroKernelTrait;
9297

9398
public function registerBundles()
9499
{
95-
// load only the bundles strictly needed for the API...
100+
$contents = require $this->getProjectDir().'/config/api_bundles.php';
101+
// ...
96102
}
97103

98104
public function getCacheDir()
@@ -107,16 +113,19 @@ files so they don't collide with the files from ``src/Kernel.php``::
107113

108114
public function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
109115
{
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');
116124
}
117125

118126
protected function configureRoutes(RouteCollectionBuilder $routes): void
119127
{
128+
$confDir = $this->getProjectDir().'/config/api';
120129
// load only the config routes strictly needed for the API
121130
}
122131
}

0 commit comments

Comments
 (0)
0