Indroduce populator service, add providers compiler pass

This commit is contained in:
ornicar 2011-04-11 19:26:10 -07:00
parent c128fac685
commit c56f4e62f5
3 changed files with 45 additions and 2 deletions

View file

@ -0,0 +1,27 @@
<?php
namespace FOQ\ElasticaBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
class AddProviderPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('foq_elastica.populator')) {
return;
}
$providers = array();
foreach ($container->findTaggedServiceIds('foq_elastica.provider') as $id => $attributes) {
$providers[] = new Reference($id);
}
$container->getDefinition('foq_elastica.populator')->setArgument(0, $providers);
}
}

View file

@ -2,8 +2,16 @@
namespace FOQ\ElasticaBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use FOQ\ElasticaBundle\DependencyInjection\Compiler\AddProviderPass;
class FOQElasticaBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new AddProviderPass());
}
}

View file

@ -7,8 +7,16 @@
<parameters>
<parameter key="foq_elastica.client.class">Elastica_Client</parameter>
<parameter key="foq_elastica.index.class">Elastica_Index</parameter>
<parameter key="foq_elastica.index_manager.class">FOQ\ElasticaBundle\IndexManager</parameter>
</parameters>
<services>
<service id="foq_elastica.index_manager" class="FOQ\ElasticaBundle\IndexManager">
<argument /> <!-- indexes -->
</service>
<service id="foq_elastica.populator" class="FOQ\ElasticaBundle\Populator">
<argument /> <!-- providers -->
</service>
</services>
</container>