Skip to content

Commit 15dc594

Browse files
committed
Merge pull request #112 from MindaugasR/master
Collecting parent class private properties annotations
2 parents ac54a6a + 5190437 commit 15dc594

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

Mapping/MetadataCollector.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
use Doctrine\Common\Annotations\FileCacheReader;
1616
use Doctrine\Common\Util\Inflector;
1717
use ONGR\ElasticsearchBundle\Annotation\Document;
18+
use ONGR\ElasticsearchBundle\Annotation\Inherit;
1819
use ONGR\ElasticsearchBundle\Annotation\MultiField;
1920
use ONGR\ElasticsearchBundle\Annotation\Property;
21+
use ONGR\ElasticsearchBundle\Annotation\Skip;
2022
use ONGR\ElasticsearchBundle\Annotation\Suggester\AbstractSuggesterProperty;
21-
use ONGR\ElasticsearchBundle\Annotation\Suggester\CompletionSuggesterProperty;
22-
use ONGR\ElasticsearchBundle\Annotation\Suggester\ContextSuggesterProperty;
2323
use ONGR\ElasticsearchBundle\Document\DocumentInterface;
2424

2525
/**
@@ -255,7 +255,7 @@ private function getDocumentReflectionMapping(\ReflectionClass $reflectionClass)
255255

256256
/**
257257
* Returns information about accessing properties from document.
258-
*
258+
*
259259
* @param \ReflectionClass $reflectionClass Document reflection class.
260260
* @param array $properties Document properties.
261261
*
@@ -373,7 +373,7 @@ private function getInfoAboutProperty($params, $alias, $reflectionClass)
373373
* @param \ReflectionClass $reflectionClass
374374
*
375375
* @return array
376-
*
376+
*
377377
* @throws \LogicException
378378
*/
379379
private function checkPropertyAccess($property, $methodPrefix, $reflectionClass)
@@ -477,7 +477,7 @@ private function getDocumentParentType($namespace)
477477
*
478478
* @param \ReflectionClass $reflectionClass Class to read properties from.
479479
* @param array $properties Properties to skip.
480-
* @param array $flag If false exludes properties, true only includes properties.
480+
* @param bool $flag If false exludes properties, true only includes properties.
481481
*
482482
* @return array
483483
*/
@@ -522,6 +522,13 @@ private function getProperties(\ReflectionClass $reflectionClass, $properties =
522522
$mapping[$type->name] = $maps;
523523
}
524524

525+
if ($parentClass = $reflectionClass->getParentClass()) {
526+
$parent_mapping = $this->getProperties(new \ReflectionClass($parentClass->getName()), $properties, $flag);
527+
if (count($parent_mapping) > 0) {
528+
$mapping = array_merge($parent_mapping, $mapping);
529+
}
530+
}
531+
525532
return $mapping;
526533
}
527534

@@ -595,7 +602,7 @@ private function getNamespace($namespace)
595602
* @param string $name
596603
*
597604
* @return string
598-
*
605+
*
599606
* @throws \LogicException
600607
*/
601608
private function getBundle($name)

Tests/app/fixture/Acme/TestBundle/Document/Item.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,44 @@ class Item implements DocumentInterface
3636
*
3737
* @ES\Property(type="float", name="price")
3838
*/
39-
public $price;
39+
protected $price;
4040

4141
/**
4242
* @var \DateTime
4343
*
4444
* @ES\Property(name="created_at", type="date")
4545
*/
46-
public $createdAt;
46+
private $createdAt;
47+
48+
/**
49+
* @return float
50+
*/
51+
public function getPrice()
52+
{
53+
return $this->price;
54+
}
55+
56+
/**
57+
* @param float $price
58+
*/
59+
public function setPrice($price)
60+
{
61+
$this->price = $price;
62+
}
63+
64+
/**
65+
* @return \DateTime
66+
*/
67+
public function getCreatedAt()
68+
{
69+
return $this->createdAt;
70+
}
71+
72+
/**
73+
* @param \DateTime $createdAt
74+
*/
75+
public function setCreatedAt($createdAt)
76+
{
77+
$this->createdAt = $createdAt;
78+
}
4779
}

0 commit comments

Comments
 (0)