Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita07c68c

Browse files
committed
minor#15407 [Configuration] Actual code example for Multiple Kernels (a-menshchikov)
This PR was merged into the 5.2 branch.Discussion----------[Configuration] Actual code example for Multiple KernelsCurrent code example based on `src/Kernel.php` from Symfony 4. This PR propose code example for Symfony 5.Commits-------a4724b6 Update multiple_kernels.rst
2 parents72c47d3 +a4724b6 commita07c68c

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

‎configuration/multiple_kernels.rst

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ Kernel. Be sure to also change the location of the cache, logs and configuration
8282
files 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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp