<?php

namespace AutoAdmin\Bundle\Seo\DependencyInjection\Compiler;

use AutoAdmin\Bundle\Seo\Sitemap\SitemapManager;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class SitemapBuilderCompilerPass implements CompilerPassInterface
{
    /**
     * @inheritDoc
     */
    public function process(ContainerBuilder $container)
    {
        $serviceArguments = [];
        $tagged = $container->findTaggedServiceIds('aa_seo.sitemap_builder');
        foreach ($tagged as $id => $value) {
            $serviceArguments[] = new Reference($id);
        }
        $def = $container->getDefinition(SitemapManager::class);
        $def->setArgument('$builders', $serviceArguments);
    }
}