KnpGaufretteBundle/DependencyInjection/Compiler/AdapterManagerPass.php

35 lines
1.1 KiB
PHP
Raw Normal View History

2011-05-08 21:04:37 +00:00
<?php
namespace Knp\Bundle\GaufretteBundle\DependencyInjection\Compiler;
2011-05-08 21:04:37 +00:00
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* Compiler pass that registers the adapters
*
* @author Antoine Hérault <antoine.herault@gmail.com>
*/
class AdapterManagerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('knp_gaufrette.adapter_manager')) {
2011-05-08 21:04:37 +00:00
return;
}
$definition = $container->getDefinition('knp_gaufrette.adapter_manager');
2011-05-08 21:04:37 +00:00
$calls = $definition->getMethodCalls();
$definition->setMethodCalls(array());
foreach ($container->findTaggedServiceIds('gaufrette.adapter') as $id => $attributes) {
if (!empty($attributes['alias'])) {
$definition->addMethodCall('set', array($attributes['alias'], new Reference($id)));
}
}
$definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
}
}