<?php


namespace AutoAdmin\Bundle\Core\DependencyInjection\Compiler;


use AutoAdmin\Bundle\Core\Setup\SetupManager;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class SetupHandlerCompilerPass implements CompilerPassInterface
{
    /**
     * @inheritDoc
     */
    public function process(ContainerBuilder $container)
    {
        /** @var Definition[] $handlers */
        $ids = $container->findTaggedServiceIds('setup.handler');
//        dump($ids);

        $setupManagerDef = $container->getDefinition(SetupManager::class);
        $handlers = [];
        foreach ($ids as $id => $v) {
            $handlerDef = $container->getDefinition($id);
            $handlers [] = new Reference($handlerDef->getClass());
        }

        $setupManagerDef->setArgument(0, $handlers);
    }
}
