Skip to content

Commit b996c48

Browse files
MihaiNeagusaimaz
authored andcommitted
Added version as metadata field. (#715)
* Added version as metadata field. * Added proper annotations and fixed PSR2 style issues. * Changed the line ending character from CRLF to LF
1 parent ca1dba0 commit b996c48

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Annotation/Version.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the ONGR package.
5+
*
6+
* (c) NFQ Technologies UAB <info@nfq.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace ONGR\ElasticsearchBundle\Annotation;
13+
14+
/**
15+
* Associates document property with _version meta-field.
16+
*
17+
* @Annotation
18+
* @Target("PROPERTY")
19+
*/
20+
final class Version implements MetaField
21+
{
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
public function getName()
26+
{
27+
return '_version';
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function getSettings()
34+
{
35+
return [];
36+
}
37+
}

Mapping/DocumentParser.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class DocumentParser
3737
const PARENT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\ParentDocument';
3838
const TTL_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Ttl';
3939
const ROUTING_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Routing';
40+
const VERSION_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Version';
4041

4142
/**
4243
* @var Reader Used to read document annotations.
@@ -177,6 +178,7 @@ private function getMetaFieldAnnotationData($property)
177178
$annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::PARENT_ANNOTATION);
178179
$annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::TTL_ANNOTATION);
179180
$annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::ROUTING_ANNOTATION);
181+
$annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::VERSION_ANNOTATION);
180182

181183
if ($annotation === null) {
182184
return null;
@@ -358,6 +360,7 @@ private function registerAnnotations()
358360
'ParentDocument',
359361
'Ttl',
360362
'Routing',
363+
'Version',
361364
];
362365

363366
foreach ($annotations as $annotation) {

0 commit comments

Comments
 (0)