Switched to manager registry for doctrine integration

This commit is contained in:
Richard Miller 2011-12-13 10:22:24 +00:00
parent b9599052f9
commit 0e3fedf3fb
8 changed files with 28 additions and 21 deletions

View file

@ -13,9 +13,9 @@ use Elastica_Document;
abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTransformerInterface
{
/**
* Repository to fetch the objects from
* Manager registry
*/
protected $objectManager = null;
protected $registry = null;
/**
* Class of the model to map to the elastica documents
@ -37,15 +37,15 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
/**
* Instantiates a new Mapper
*
* @param object $objectManager
* @param object $registry
* @param string $objectClass
* @param array $options
*/
public function __construct($objectManager, $objectClass, array $options = array())
public function __construct($registry, $objectClass, array $options = array())
{
$this->objectManager = $objectManager;
$this->objectClass = $objectClass;
$this->options = array_merge($this->options, $options);
$this->registry = $registry;
$this->objectClass = $objectClass;
$this->options = array_merge($this->options, $options);
}
/**
@ -60,7 +60,6 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
$ids = array_map(function($elasticaObject) {
return $elasticaObject->getId();
}, $elasticaObjects);
$objects = $this->findByIdentifiers($this->objectClass, $this->options['identifier'], $ids, $this->options['hydrate']);
$identifierGetter = 'get'.ucfirst($this->options['identifier']);

View file

@ -19,11 +19,11 @@ abstract class AbstractProvider implements ProviderInterface
protected $type;
/**
* Domain model object manager
* Manager registry
*
* @var object
*/
protected $objectManager;
protected $registry;
/**
* Object persister
@ -43,10 +43,10 @@ abstract class AbstractProvider implements ProviderInterface
'query_builder_method' => 'createQueryBuilder'
);
public function __construct(Elastica_Type $type, $objectManager, ObjectPersisterInterface $objectPersister, $objectClass, array $options = array())
public function __construct(Elastica_Type $type, $registry, ObjectPersisterInterface $objectPersister, $objectClass, array $options = array())
{
$this->type = $type;
$this->objectManager = $objectManager;
$this->registry = $registry;
$this->objectClass = $objectClass;
$this->objectPersister = $objectPersister;
$this->options = array_merge($this->options, $options);
@ -70,7 +70,7 @@ abstract class AbstractProvider implements ProviderInterface
$this->objectPersister->insertMany($objects);
if ($this->options['clear_object_manager']) {
$this->objectManager->clear();
$this->registry->getManagerForClass($this->objectClass)->clear();
}
$stepNbObjects = count($objects);

View file

@ -23,7 +23,8 @@ class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
*/
protected function findByIdentifiers($class, $identifierField, array $identifierValues, $hydrate)
{
return $this->objectManager
return $this->registry
->getManagerForClass($class)
->createQueryBuilder($class)
->field($identifierField)->in($identifierValues)
->hydrate($hydrate)

View file

@ -37,6 +37,9 @@ class Provider extends AbstractProvider
**/
protected function createQueryBuilder()
{
return $this->objectManager->getRepository($this->objectClass)->{$this->options['query_builder_method']}();
return $this->registry
->getManagerForClass($this->objectClass)
->getRepository($this->objectClass)
->{$this->options['query_builder_method']}();
}
}

View file

@ -28,7 +28,8 @@ class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
return array();
}
$hydrationMode = $hydrate ? Query::HYDRATE_OBJECT : Query::HYDRATE_ARRAY;
$qb = $this->objectManager
$qb = $this->registry
->getManagerForClass($class)
->getRepository($class)
->createQueryBuilder('o');
/* @var $qb \Doctrine\ORM\QueryBuilder */

View file

@ -44,6 +44,9 @@ class Provider extends AbstractProvider
**/
protected function createQueryBuilder()
{
return $this->objectManager->getRepository($this->objectClass)->{$this->options['query_builder_method']}('a');
return $this->registry
->getManagerForClass($this->objectClass)
->getRepository($this->objectClass)
->{$this->options['query_builder_method']}('a');
}
}

View file

@ -8,7 +8,7 @@
<service id="foq_elastica.provider.prototype.mongodb" class="FOQ\ElasticaBundle\Doctrine\MongoDB\Provider" public="false" abstract="true">
<argument /> <!-- type -->
<argument type="service" id="doctrine.odm.mongodb.document_manager" />
<argument type="service" id="doctrine.odm.mongodb" />
<argument /> <!-- object persister -->
<argument /> <!-- model -->
<argument type="collection" /> <!-- options -->
@ -22,7 +22,7 @@
</service>
<service id="foq_elastica.elastica_to_model_transformer.prototype.mongodb" class="FOQ\ElasticaBundle\Doctrine\MongoDB\ElasticaToModelTransformer" public="false">
<argument type="service" id="doctrine.odm.mongodb.document_manager" />
<argument type="service" id="doctrine.odm.mongodb" />
<argument /> <!-- model -->
<argument type="collection" /> <!-- options -->
</service>

View file

@ -8,7 +8,7 @@
<service id="foq_elastica.provider.prototype.orm" class="FOQ\ElasticaBundle\Doctrine\ORM\Provider" public="false" abstract="true">
<argument /> <!-- type -->
<argument type="service" id="doctrine.orm.entity_manager" />
<argument type="service" id="doctrine" />
<argument /> <!-- object persister -->
<argument /> <!-- model -->
<argument type="collection" /> <!-- options -->
@ -22,7 +22,7 @@
</service>
<service id="foq_elastica.elastica_to_model_transformer.prototype.orm" class="FOQ\ElasticaBundle\Doctrine\ORM\ElasticaToModelTransformer" public="false">
<argument type="service" id="doctrine.orm.entity_manager" />
<argument type="service" id="doctrine" />
<argument /> <!-- model -->
<argument type="collection" /> <!-- options -->
</service>