function KernelDestructionSubscriber::onKernelTerminate

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php \Drupal\Core\EventSubscriber\KernelDestructionSubscriber::onKernelTerminate()
  2. 10 core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php \Drupal\Core\EventSubscriber\KernelDestructionSubscriber::onKernelTerminate()
  3. 11.x core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php \Drupal\Core\EventSubscriber\KernelDestructionSubscriber::onKernelTerminate()

Invoked by the terminate kernel event.

Parameters

\Symfony\Component\HttpKernel\Event\TerminateEvent $event: The event object.

File

core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php, line 45

Class

KernelDestructionSubscriber
Destructs services that are initiated and tagged with "needs_destruction".

Namespace

Drupal\Core\EventSubscriber

Code

public function onKernelTerminate(TerminateEvent $event) {
    foreach ($this->services as $id) {
        // Check if the service was initialized during this request, destruction
        // is not necessary if the service was not used.
        if ($this->container
            ->initialized($id)) {
            $service = $this->container
                ->get($id);
            $service->destruct();
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.