FOSElasticaBundle/Transformer/ModelToElasticaIdentifierTransformer.php

28 lines
728 B
PHP
Raw Normal View History

<?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.
*/
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.
*
* @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
return new Document($identifier);
}
}