FOSElasticaBundle/Propel/Lookup.php

55 lines
1.3 KiB
PHP
Raw Normal View History

2014-04-25 13:31:04 +02:00
<?php
namespace FOS\ElasticaBundle\Propel;
use Doctrine\Common\Util\Inflector;
use FOS\ElasticaBundle\Type\LookupInterface;
2014-05-15 14:55:35 +02:00
use FOS\ElasticaBundle\Type\TypeConfiguration;
2014-04-25 13:31:04 +02:00
class Lookup implements LookupInterface
{
/**
* Returns the lookup key.
*
* @return string
*/
public function getKey()
{
return 'propel';
}
/**
* Look up objects of a specific type with ids as supplied.
*
2014-05-15 14:55:35 +02:00
* @param TypeConfiguration $configuration
2014-04-25 13:31:04 +02:00
* @param int[] $ids
* @return object[]
*/
2014-05-15 14:55:35 +02:00
public function lookup(TypeConfiguration $configuration, array $ids)
2014-04-25 13:31:04 +02:00
{
$query = $this->createQuery($configuration, $ids);
if (!$configuration->isHydrate()) {
return $query->toArray();
}
return $query->find();
}
/**
* Create a query to use in the findByIdentifiers() method.
*
2014-05-15 14:55:35 +02:00
* @param TypeConfiguration $configuration
2014-04-25 13:31:04 +02:00
* @param array $ids
* @return \ModelCriteria
*/
2014-05-15 14:55:35 +02:00
protected function createQuery(TypeConfiguration $configuration, array $ids)
2014-04-25 13:31:04 +02:00
{
$queryClass = $configuration->getModelClass() . 'Query';
$query = $queryClass::create();
$filterMethod = 'filterBy' . Inflector::camelize($configuration->getIdentifierProperty());
return $query->$filterMethod($ids);
}
}