2013-07-17 08:58:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FOS\ElasticaBundle\Transformer;
|
|
|
|
|
|
|
|
use Elastica\Document;
|
|
|
|
|
|
|
|
/**
|
2013-07-18 10:54:11 +02:00
|
|
|
* Creates an Elastica document with the ID of
|
2015-03-12 11:20:00 +01:00
|
|
|
* the Doctrine object as Elastica document ID.
|
2013-07-17 08:58:15 +02:00
|
|
|
*/
|
|
|
|
class ModelToElasticaIdentifierTransformer extends ModelToElasticaAutoTransformer
|
|
|
|
{
|
|
|
|
/**
|
2015-03-12 11:20:00 +01:00
|
|
|
* Creates an elastica document with the id of the doctrine object as id.
|
2013-07-17 08:58:15 +02:00
|
|
|
*
|
|
|
|
* @param object $object the object to convert
|
|
|
|
* @param array $fields the keys we want to have in the returned array
|
|
|
|
*
|
|
|
|
* @return Document
|
|
|
|
**/
|
|
|
|
public function transform($object, array $fields)
|
|
|
|
{
|
|
|
|
$identifier = $this->propertyAccessor->getValue($object, $this->options['identifier']);
|
2014-06-23 15:05:57 +02:00
|
|
|
|
2013-07-17 08:58:15 +02:00
|
|
|
return new Document($identifier);
|
|
|
|
}
|
|
|
|
}
|