RegisterServicesForDestructionPass.php 862 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Drupal\Core\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\ContainerBuilder;
  4. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  5. /**
  6. * Adds services tagged "needs_destruction" to the "kernel_destruct_subscriber"
  7. * service.
  8. *
  9. * @see \Drupal\Core\DestructableInterface
  10. */
  11. class RegisterServicesForDestructionPass implements CompilerPassInterface {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function process(ContainerBuilder $container) {
  16. if (!$container->hasDefinition('kernel_destruct_subscriber')) {
  17. return;
  18. }
  19. $definition = $container->getDefinition('kernel_destruct_subscriber');
  20. $services = $container->findTaggedServiceIds('needs_destruction');
  21. foreach ($services as $id => $attributes) {
  22. $definition->addMethodCall('registerService', [$id]);
  23. }
  24. }
  25. }