From 4ad7d9a5257e88ebb3aea64d51595cfef63537e9 Mon Sep 17 00:00:00 2001 From: ornicar Date: Thu, 14 Apr 2011 16:22:14 -0700 Subject: [PATCH] Add MapperInterface with a doctrine implementation --- Mapper/DoctrineMapper.php | 60 +++++++++++++++++++++++++++++++++++++++ MapperInterface.php | 17 +++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Mapper/DoctrineMapper.php create mode 100644 MapperInterface.php diff --git a/Mapper/DoctrineMapper.php b/Mapper/DoctrineMapper.php new file mode 100644 index 0000000..a7a1242 --- /dev/null +++ b/Mapper/DoctrineMapper.php @@ -0,0 +1,60 @@ +objectRepository = $objectRepository; + $this->identifier = $identifier; + } + + /** + * Transforms an array of elastica objects into an array of + * model objects fetched from the doctrine repository + * + * @return array + **/ + public function fromElasticaObjects(array $elasticaObjects) + { + $ids = array_map(function($elasticaObject) { + return $elasticaObject->getId(); + }, $elasticaObjects); + + return $this->objectRepository + ->createQueryBuilder() + ->field($this->identifier)->in($ids) + ->getQuery() + ->execute(); + } + +} diff --git a/MapperInterface.php b/MapperInterface.php new file mode 100644 index 0000000..c0a7d08 --- /dev/null +++ b/MapperInterface.php @@ -0,0 +1,17 @@ +