Merge branch '2.0'

Conflicts:
	Doctrine/AbstractElasticaToModelTransformer.php
	Doctrine/MongoDB/ElasticaToModelTransformer.php
	Doctrine/ORM/ElasticaToModelTransformer.php
	composer.json
This commit is contained in:
Richard Miller 2012-07-10 21:37:23 +01:00
commit 2732296aed
5 changed files with 18 additions and 19 deletions

View file

@ -72,7 +72,7 @@ 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']);
$objects = $this->findByIdentifiers($ids, $this->options['hydrate']);
if (count($objects) < count($elasticaObjects)) {
throw new \RuntimeException('Cannot find corresponding Doctrine objects for all Elastica results.');
};
@ -104,11 +104,9 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
/**
* Fetches objects by theses identifier values
*
* @param string $class the model class
* @param string $identifierField like 'id'
* @param array $identifierValues ids values
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
* @return array of objects or arrays
*/
protected abstract function findByIdentifiers($class, $identifierField, array $identifierValues, $hydrate);
protected abstract function findByIdentifiers(array $identifierValues, $hydrate);
}

View file

@ -15,18 +15,16 @@ class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
/**
* Fetch objects for theses identifier values
*
* @param string $class the model class
* @param string $identifierField like 'id'
* @param array $identifierValues ids values
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
* @return array of objects or arrays
*/
protected function findByIdentifiers($class, $identifierField, array $identifierValues, $hydrate)
protected function findByIdentifiers(array $identifierValues, $hydrate)
{
return $this->registry
->getManagerForClass($class)
->createQueryBuilder($class)
->field($identifierField)->in($identifierValues)
->getManagerForClass($this->objectClass)
->createQueryBuilder($this->objectClass)
->field($this->options['identifier'])->in($identifierValues)
->hydrate($hydrate)
->getQuery()
->execute()

View file

@ -16,24 +16,22 @@ class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
/**
* Fetch objects for theses identifier values
*
* @param string $class the model class
* @param string $identifierField like 'id'
* @param array $identifierValues ids values
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
* @return array of objects or arrays
*/
protected function findByIdentifiers($class, $identifierField, array $identifierValues, $hydrate)
protected function findByIdentifiers(array $identifierValues, $hydrate)
{
if (empty($identifierValues)) {
return array();
}
$hydrationMode = $hydrate ? Query::HYDRATE_OBJECT : Query::HYDRATE_ARRAY;
$qb = $this->registry
->getManagerForClass($class)
->getRepository($class)
->getManagerForClass($this->objectClass)
->getRepository($this->objectClass)
->createQueryBuilder('o');
/* @var $qb \Doctrine\ORM\QueryBuilder */
$qb->where($qb->expr()->in('o.'.$identifierField, ':values'))
$qb->where($qb->expr()->in('o.'.$this->options['identifier'], ':values'))
->setParameter('values', $identifierValues);
return $qb->getQuery()->setHydrationMode($hydrationMode)->execute();

View file

@ -58,7 +58,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
return $elasticaObject->getId();
}, $elasticaObjects);
$objects = $this->findByIdentifiers($this->objectClass, $this->options['identifier'], $ids, $this->options['hydrate']);
$objects = $this->findByIdentifiers($ids, $this->options['hydrate']);
$identifierProperty = new PropertyPath($this->options['identifier']);
@ -109,13 +109,13 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
* @return array of objects or arrays
*/
protected function findByIdentifiers($class, $identifierField, array $identifierValues, $hydrate)
protected function findByIdentifiers(array $identifierValues, $hydrate)
{
if (empty($identifierValues)) {
return array();
}
$query = $this->createQuery($class, $identifierField, $identifierValues);
$query = $this->createQuery($this->objectClass, $this->options['identifier'], $identifierValues);
if (!$hydrate) {
return $query->toArray();

View file

@ -17,6 +17,11 @@
"symfony/form": "2.1.*",
"ruflin/elastica": ">=0.19.3"
},
"require-dev":{
"doctrine/orm":"2.2.*",
"doctrine/mongodb-odm":"dev-master",
"propel/propel1":"1.6.*"
},
"suggest": {
"doctrine/orm": "2.2.*",
"doctrine/mongodb-odm": "dev-master",