function BootableCommandTrait::boot
Boots up a Drupal environment.
Return value
\Drupal\Core\DrupalKernelInterface The Drupal kernel.
Throws
\Exception Exception thrown if kernel does not boot.
1 call to BootableCommandTrait::boot()
- RecipeInfoCommand::execute in core/
lib/ Drupal/ Core/ Recipe/ RecipeInfoCommand.php
File
-
core/
lib/ Drupal/ Core/ Command/ BootableCommandTrait.php, line 38
Class
- BootableCommandTrait
- Contains helper methods for console commands that boot up Drupal.
Namespace
Drupal\Core\CommandCode
protected function boot() : DrupalKernelInterface {
$kernel = new DrupalKernel('prod', $this->classLoader);
$kernel::bootEnvironment();
$kernel->setSitePath($this->getSitePath());
Settings::initialize($kernel->getAppRoot(), $kernel->getSitePath(), $this->classLoader);
$kernel->boot();
$request = Request::createFromGlobals();
$kernel->preHandle($request);
// Try to register an event listener to properly terminate the Drupal kernel
// when the console application itself terminates. This ensures that
// `kernel.destructable_services` are destructed, which in turn ensures that
// the router can be rebuilt if needed, along with other services that
// perform actions on destruct.
$event_dispatcher = $kernel->getContainer()
->get(EventDispatcherInterface::class);
if ($kernel instanceof TerminableInterface && $event_dispatcher instanceof ComponentEventDispatcherInterface) {
$event_dispatcher->addListener(ConsoleEvents::TERMINATE, function () use ($kernel, $request) : void {
$kernel->terminate($request, new Response());
});
$this->getApplication()
->setDispatcher($event_dispatcher);
}
return $kernel;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.