Skip to content

Commit

Permalink
Added version as metadata field. (#715)
Browse files Browse the repository at this point in the history
* Added version as metadata field.

* Added proper annotations and fixed PSR2 style issues.

* Changed the line ending character from CRLF to LF
  • Loading branch information
MihaiNeagu authored and saimaz committed Dec 15, 2016
1 parent ca1dba0 commit b996c48
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Annotation/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\Annotation;

/**
* Associates document property with _version meta-field.
*
* @Annotation
* @Target("PROPERTY")
*/
final class Version implements MetaField
{
/**
* {@inheritdoc}
*/
public function getName()
{
return '_version';
}

/**
* {@inheritdoc}
*/
public function getSettings()
{
return [];
}
}
3 changes: 3 additions & 0 deletions Mapping/DocumentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DocumentParser
const PARENT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\ParentDocument';
const TTL_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Ttl';
const ROUTING_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Routing';
const VERSION_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Version';

/**
* @var Reader Used to read document annotations.
Expand Down Expand Up @@ -177,6 +178,7 @@ private function getMetaFieldAnnotationData($property)
$annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::PARENT_ANNOTATION);
$annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::TTL_ANNOTATION);
$annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::ROUTING_ANNOTATION);
$annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::VERSION_ANNOTATION);

if ($annotation === null) {
return null;
Expand Down Expand Up @@ -358,6 +360,7 @@ private function registerAnnotations()
'ParentDocument',
'Ttl',
'Routing',
'Version',
];

foreach ($annotations as $annotation) {
Expand Down

0 comments on commit b996c48

Please sign in to comment.