You are here

protected function TaggedHandlersPass::processServiceIdCollectorPass in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php \Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass::processServiceIdCollectorPass()
  2. 9 core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php \Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass::processServiceIdCollectorPass()

Processes a service collector ID service pass.

Parameters

array $pass: The service collector pass data.

string $consumer_id: The consumer service ID.

\Symfony\Component\DependencyInjection\ContainerBuilder $container: The service container.

1 call to TaggedHandlersPass::processServiceIdCollectorPass()
TaggedHandlersPass::process in core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php
Finds services tagged with 'service_collector' or 'service_id_collector', then finds all corresponding tagged services.

File

core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php, line 230

Class

TaggedHandlersPass
Collects services to add/inject them into a consumer service.

Namespace

Drupal\Core\DependencyInjection\Compiler

Code

protected function processServiceIdCollectorPass(array $pass, $consumer_id, ContainerBuilder $container) {
  $tag = $pass['tag'] ?? $consumer_id;
  $required = $pass['required'] ?? FALSE;
  $consumer = $container
    ->getDefinition($consumer_id);

  // Find all tagged handlers.
  $handlers = [];
  foreach ($this->tagCache[$tag] ?? [] as $id => $attributes) {
    $handlers[$id] = $attributes[0]['priority'] ?? 0;
  }
  if ($required && empty($handlers)) {
    throw new LogicException(sprintf("At least one service tagged with '%s' is required.", $tag));
  }

  // Sort all handlers by priority.
  arsort($handlers, SORT_NUMERIC);
  $consumer
    ->addArgument(array_keys($handlers));
}