src/DependencyInjection/TemplateFilterPass.php
private function registerTaggedServices(
        ContainerBuilder $container,
        string $definitionId,
        string $tagName,
        $argumentIndex = 0
    ): bool {
        if (!$container->has($definitionId)) {
            return false;
        }

        $definition       = $container->findDefinition($definitionId);
        $taggedServiceIds = $container->findTaggedServiceIds($tagName);
        $services         = (array) $definition->getArgument($argumentIndex);

        foreach (array_keys($taggedServiceIds) as $serviceId) {
            $services[] = new Reference($serviceId);
        }

        $definition->replaceArgument(0, $services);

        return true;
    }
private function registerTaggedServices(
        ContainerBuilder $container,
        string $definitionId,
        string $tagName,
        $argumentIndex = 0
    ): bool {
        if (!$container->has($definitionId)) {
            return false;
        }

        $definition       = $container->findDefinition($definitionId);
        $taggedServiceIds = $container->findTaggedServiceIds($tagName);
        $services         = (array) $definition->getArgument($argumentIndex);

        foreach (array_keys($taggedServiceIds) as $serviceId) {
            $services[] = new Reference($serviceId);
        }

        $definition->replaceArgument(0, $services);

        return true;
    }
Register a tagged services to an definition argument. Returns false if service does not exist.

@param ContainerBuilder $container     Container builder.
@param string           $definitionId  Service definition id.
@param string           $tagName       Tag name.
@param int              $argumentIndex Index of the argument being replaced.

@return bool