vendor/friendsofsymfony/elastica-bundle/src/Doctrine/ORM/ElasticaToModelTransformer.php line 51

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSElasticaBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace FOS\ElasticaBundle\Doctrine\ORM;
  11. use Doctrine\ORM\Query;
  12. use FOS\ElasticaBundle\Doctrine\AbstractElasticaToModelTransformer;
  13. /**
  14.  * Maps Elastica documents with Doctrine objects
  15.  * This mapper assumes an exact match between
  16.  * elastica documents ids and doctrine object ids.
  17.  */
  18. class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
  19. {
  20.     const ENTITY_ALIAS 'o';
  21.     /**
  22.      * Fetch objects for theses identifier values.
  23.      *
  24.      * @param array $identifierValues ids values
  25.      * @param bool  $hydrate          whether or not to hydrate the objects, false returns arrays
  26.      *
  27.      * @return array of objects or arrays
  28.      */
  29.     protected function findByIdentifiers(array $identifierValues$hydrate)
  30.     {
  31.         if (empty($identifierValues)) {
  32.             return [];
  33.         }
  34.         $hydrationMode $hydrate Query::HYDRATE_OBJECT Query::HYDRATE_ARRAY;
  35.         $qb $this->getEntityQueryBuilder();
  36.         $qb->andWhere($qb->expr()->in(static::ENTITY_ALIAS.'.'.$this->options['identifier'], ':values'))
  37.             ->setParameter('values'$identifierValues);
  38.         $query $qb->getQuery();
  39.         foreach ($this->options['hints'] as $hint) {
  40.             $query->setHint($hint['name'], $hint['value']);
  41.         }
  42.         return $query->setHydrationMode($hydrationMode)->execute();
  43.     }
  44.     /**
  45.      * Retrieves a query builder to be used for querying by identifiers.
  46.      *
  47.      * @return \Doctrine\ORM\QueryBuilder
  48.      */
  49.     protected function getEntityQueryBuilder()
  50.     {
  51.         $repository $this->registry
  52.             ->getManagerForClass($this->objectClass)
  53.             ->getRepository($this->objectClass);
  54.         return $repository->{$this->options['query_builder_method']}(static::ENTITY_ALIAS);
  55.     }
  56. }