public function KernelDestructionSubscriber::onKernelTerminate

Invoked by the terminate kernel event.

Parameters

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

File

drupal/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php, line 46
Contains \Drupal\Core\EventSubscriber\KernelDestructionSubscriber.

Class

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

Namespace

Drupal\Core\EventSubscriber

Code

public function onKernelTerminate(PostResponseEvent $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();
    }
  }
}