Skip to content

Commit

Permalink
Merge pull request #35 from thomasblass/ObjectIdentifierTransformer
Browse files Browse the repository at this point in the history
[Task] Add ObjectIdentifierTransformer
  • Loading branch information
skurfuerst committed Nov 10, 2015
2 parents 97698dd + 757ab45 commit f645237
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
namespace Flowpack\ElasticSearch\Indexer\Object\Transform;

/* *
* This script belongs to the TYPO3 Flow package "Flowpack.ElasticSearch".*
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Persistence\PersistenceManagerInterface;

/**
* @Flow\Scope("singleton")
*/
class ObjectIdentifierTransformer implements TransformerInterface {

/**
* @Flow\Inject
* @var PersistenceManagerInterface
*/
protected $persistenceManager;

/**
* Returns the Elasticsearch type this transform() method returns
*
* @return string
*/
public function getTargetMappingType() {
return 'string';
}

/**
* @param mixed $source
* @param \Flowpack\ElasticSearch\Annotations\Transform $annotation
* @return string
*/
public function transformByAnnotation($source, \Flowpack\ElasticSearch\Annotations\Transform $annotation) {
if($source != null) {
return $this->persistenceManager->getIdentifierByObject($source);
}
return '';
}
}

0 comments on commit f645237

Please sign in to comment.