<?php
/**
 * Compiler Pass for loading tags
 *
 * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
 */
namespace VisualM\TagManagerBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;

class TagsCompilerPass implements CompilerPassInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('visualm.tag_manager.util.tags_registry')) {
            return;
        }

        $registry = $container->getDefinition(
            'visualm.tag_manager.manager.meta_tag_set'
        );

        $tags = $container->findTaggedServiceIds(
            'visualm.tag_manager.tagset.factory'
        );

        foreach ($tags as $id=>$tag) {
            foreach ($tag as $attribute) {
                $registry->addMethodCall('addFactory', array(
                    new Reference($id),
                    $id,
               ));
            }
        }
    }
}




