Made default manager configurable
This commit is contained in:
parent
ba976e3a41
commit
510d411055
|
@ -26,6 +26,7 @@ class Configuration
|
|||
->children()
|
||||
->scalarNode('default_client')->end()
|
||||
->scalarNode('default_index')->end()
|
||||
->scalarNode('default_manager')->defaultValue('orm')->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
|
|
|
@ -53,15 +53,7 @@ class FOQElasticaExtension extends Extension
|
|||
$container->setAlias('foq_elastica.client', sprintf('foq_elastica.client.%s', $config['default_client']));
|
||||
$container->setAlias('foq_elastica.index', sprintf('foq_elastica.index.%s', $config['default_index']));
|
||||
|
||||
if (0 < count($this->loadedDrivers)) {
|
||||
$defaultManager = $this->loadedDrivers[0];
|
||||
} else {
|
||||
$defaultManager = 'orm';
|
||||
}
|
||||
|
||||
if ('propel' !== $defaultManager) {
|
||||
$container->setAlias('foq_elastica.manager', sprintf('foq_elastica.manager.%s', $defaultManager));
|
||||
}
|
||||
$this->createDefaultManagerAlias($config['default_manager'], $container);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -370,4 +362,22 @@ class FOQElasticaExtension extends Extension
|
|||
$loader->load($driver.'.xml');
|
||||
$this->loadedDrivers[] = $driver;
|
||||
}
|
||||
|
||||
protected function createDefaultManagerAlias($defaultManager, ContainerBuilder $container)
|
||||
{
|
||||
if (0 == count($this->loadedDrivers)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (count($this->loadedDrivers) > 1
|
||||
&& in_array($defaultManager, $this->loadedDrivers)
|
||||
) {
|
||||
$defaultManagerService = $defaultManager;
|
||||
} else {
|
||||
$defaultManagerService = $this->loadedDrivers[0];
|
||||
}
|
||||
|
||||
$container->setAlias('foq_elastica.manager', sprintf('foq_elastica.manager.%s', $defaultManagerService));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -63,8 +63,6 @@
|
|||
<argument /> <!-- options -->
|
||||
</service>
|
||||
|
||||
<service id="foq_elastica.manager" class="%foq_elastica.manager.class%" />
|
||||
|
||||
</services>
|
||||
|
||||
</container>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<argument type="collection" /> <!-- options -->
|
||||
</service>
|
||||
|
||||
<service id="foq_elastica.manager.mongodb" class="FOQ\ElasticaBundle\Manager\RepositoryManager">
|
||||
<service id="foq_elastica.manager.mongodb" class="FOQ\ElasticaBundle\Doctrine\RepositoryManager">
|
||||
<argument type="service" id="doctrine.odm.mongodb"/>
|
||||
<argument type="service" id="annotation_reader"/>
|
||||
</service>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<argument type="collection" /> <!-- options -->
|
||||
</service>
|
||||
|
||||
<service id="foq_elastica.manager.orm" class="FOQ\ElasticaBundle\Manager\RepositoryManager">
|
||||
<service id="foq_elastica.manager.orm" class="FOQ\ElasticaBundle\Doctrine\RepositoryManager">
|
||||
<argument type="service" id="doctrine"/>
|
||||
<argument type="service" id="annotation_reader"/>
|
||||
</service>
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
<argument type="collection" /> <!-- options -->
|
||||
</service>
|
||||
|
||||
<service id="foq_elastica.manager.propel" class="%foq_elastica.manager.class%"/>
|
||||
|
||||
</services>
|
||||
|
||||
</container>
|
||||
|
|
Loading…
Reference in a new issue