Loading core/lib/Drupal/Core/Command/BootableCommandTrait.php +22 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,12 @@ use Drupal\Core\DrupalKernel; use Drupal\Core\DrupalKernelInterface; use Drupal\Core\Site\Settings; use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\EventDispatcher\EventDispatcherInterface as ComponentEventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\TerminableInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Contains helper methods for console commands that boot up Drupal. Loading Loading @@ -36,7 +41,23 @@ protected function boot(): DrupalKernelInterface { $kernel->setSitePath($this->getSitePath()); Settings::initialize($kernel->getAppRoot(), $kernel->getSitePath(), $this->classLoader); $kernel->boot(); $kernel->preHandle(Request::createFromGlobals()); $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; } Loading Loading
core/lib/Drupal/Core/Command/BootableCommandTrait.php +22 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,12 @@ use Drupal\Core\DrupalKernel; use Drupal\Core\DrupalKernelInterface; use Drupal\Core\Site\Settings; use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\EventDispatcher\EventDispatcherInterface as ComponentEventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\TerminableInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Contains helper methods for console commands that boot up Drupal. Loading Loading @@ -36,7 +41,23 @@ protected function boot(): DrupalKernelInterface { $kernel->setSitePath($this->getSitePath()); Settings::initialize($kernel->getAppRoot(), $kernel->getSitePath(), $this->classLoader); $kernel->boot(); $kernel->preHandle(Request::createFromGlobals()); $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; } Loading