RegisterServicesForDestructionPass.php

Same filename and directory in other branches
  1. 11.x core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php
  2. 10 core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php
  3. 9 core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php
  4. 8.9.x core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php

Namespace

Drupal\Core\DependencyInjection\Compiler

File

core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php

View source
<?php

namespace Drupal\Core\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
 * Adds services to the "kernel.destructable_services" container parameter.
 *
 * Only services tagged with "needs_destruction" are added.
 *
 * @see \Drupal\Core\DestructableInterface
 */
class RegisterServicesForDestructionPass implements CompilerPassInterface {
  use PriorityTaggedServiceTrait;
  
  /**
   * {@inheritdoc}
   */
  public function process(ContainerBuilder $container) : void {
    $service_ids = array_values(array_map(strval(...), $this->findAndSortTaggedServices('needs_destruction', $container)));
    $container->setParameter('kernel.destructable_services', $service_ids);
  }

}

Classes

Title Deprecated Summary
RegisterServicesForDestructionPass Adds services to the "kernel.destructable_services" container parameter.

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