2011-05-08 21:04:37 +00:00
|
|
|
<?php
|
|
|
|
|
2011-07-03 09:38:38 +00:00
|
|
|
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 adapter factories
|
|
|
|
*
|
|
|
|
* @author Antoine Hérault <antoine.herault@gmail.com>
|
|
|
|
*/
|
|
|
|
class AdapterFactoryManagerPass implements CompilerPassInterface
|
|
|
|
{
|
|
|
|
public function process(ContainerBuilder $container)
|
|
|
|
{
|
2011-07-03 09:38:38 +00:00
|
|
|
if (!$container->hasDefinition('knp_gaufrette.adapter_factory_manager')) {
|
2011-05-08 21:04:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-03 09:38:38 +00:00
|
|
|
$definition = $container->getDefinition('knp_gaufrette.adapter_factory_manager');
|
2011-05-08 21:04:37 +00:00
|
|
|
|
|
|
|
$calls = $definition->getMethodCalls();
|
|
|
|
$definition->setMethodCalls(array());
|
|
|
|
|
|
|
|
foreach ($container->findTaggedServiceIds('gaufrette.adapter_factory') as $id => $attributes) {
|
|
|
|
if (!empty($attributes['type'])) {
|
|
|
|
$definition->addMethodCall('set', array($attributes['type'], new Reference($id)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
|
|
|
|
}
|
|
|
|
}
|