<?php

namespace AutoAdmin\Bundle\Admin\DependencyInjection\Compiler;

use AutoAdmin\Bundle\Admin\Attribute\Loader\AttributeLoader;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class TypeGuesserCompilerPass implements CompilerPassInterface
{
    /**
     * @inheritDoc
     */
    public function process(ContainerBuilder $container)
    {
        $definitions = $container->findTaggedServiceIds('aa_admin.type_guesser');
        $attributeLoader = new Reference(AttributeLoader::class);
        foreach ($definitions as $id => $value) {
            $def = $container->getDefinition($id);
            $def->addMethodCall('setAttributeLoader', [$attributeLoader]);
        }
    }
}
