Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php
- 9 core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php
Namespace
Drupal\Core\EventSubscriber
File
core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php
View source
<?php
namespace Drupal\Core\EventSubscriber;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class KernelDestructionSubscriber implements EventSubscriberInterface, ContainerAwareInterface {
use ContainerAwareTrait;
protected $services = [];
public function registerService($id) {
$this->services[] = $id;
}
public function onKernelTerminate(TerminateEvent $event) {
foreach ($this->services as $id) {
if ($this->container
->initialized($id)) {
$service = $this->container
->get($id);
$service
->destruct();
}
}
}
public static function getSubscribedEvents() : array {
$events[KernelEvents::TERMINATE][] = [
'onKernelTerminate',
100,
];
return $events;
}
}
Classes