8000 Update multiple_kernels.rst by amine-betari · Pull Request #12724 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Update multiple_kernels.rst #12724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions configuration/multiple_kernels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,50 @@ files so they don't collide with the files from ``src/Kernel.php``::

class ApiKernel extends Kernel
{
// ...
use MicroKernelTrait;

public function registerBundles()
{
// load only the bundles strictly needed for the API...
// load only the bundles strictly needed for the API
$contents = require $this->getProjectDir().'/config/api_bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}

public function getProjectDir(): string
{
return \dirname(__DIR__);
}

public function getCacheDir()
public function getCacheDir(): string
{
return dirname(__DIR__).'/var/cache/api/'.$this->getEnvironment();
return $this->getProjectDir().'/var/cache/api/'.$this->getEnvironment();
}

public function getLogDir()
public function getLogDir(): string
{
return dirname(__DIR__).'/var/log/api';
return $this->getProjectDir().'/var/log/api';
}

public function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
// load only the config files strictly needed for the API
$confDir = $this->getProjectDir().'/config';
$loader->load($confDir.'/api/*'.self::CONFIG_EXTS, 'glob');
if (is_dir($confDir.'/api/'.$this->environment)) {
$loader->load($confDir.'/api/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
}
$container->addResource(new FileResource($this->getProjectDir().'/config/api_bundles.php'));
$container->setParameter('container.dumper.inline_factories', true);
$confDir = $this->getProjectDir().'/config/api';

$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
}

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

Expand Down
0