1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pgs\ElasticOM\Annotation\Visitor; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
6
|
|
|
use Pgs\ElasticOM\Annotation\BaseAnnotation; |
7
|
|
|
|
8
|
|
|
class AnnotationVisitor |
9
|
|
|
{ |
10
|
|
|
/** @var AnnotationReader */ |
11
|
|
|
protected $reader; |
12
|
|
|
|
13
|
|
|
/** @var ClassMetadataVisiteeFactory */ |
14
|
|
|
protected $classMetadataFactory; |
15
|
|
|
|
16
|
3 |
|
public function __construct(AnnotationReader $reader, ClassMetadataVisiteeFactory $classMetadataFactory) |
17
|
|
|
{ |
18
|
3 |
|
$this->reader = $reader; |
19
|
3 |
|
$this->classMetadataFactory = $classMetadataFactory; |
20
|
3 |
|
} |
21
|
|
|
|
22
|
1 |
|
public function visit(ClassMetadataVisitee $classMetadata) |
23
|
|
|
{ |
24
|
1 |
|
$classConfig = []; |
25
|
1 |
|
foreach ($classMetadata->getClassReflection()->getProperties() as $property) { |
26
|
1 |
|
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { |
27
|
|
|
/* @var $annotation BaseAnnotation */ |
28
|
1 |
|
if (!isset($classConfig[$property->getName()])) { |
29
|
1 |
|
$classConfig[$property->getName()] = []; |
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
$propertyConfig = $annotation->getRawValues(); |
33
|
1 |
|
if (array_key_exists('targetClass', $propertyConfig) |
34
|
1 |
|
&& array_key_exists('type', $propertyConfig) |
35
|
1 |
|
&& in_array($propertyConfig['type'], ['object', 'nested'], true) |
36
|
|
|
) { |
37
|
1 |
|
$nestedClass = $this->classMetadataFactory->create($propertyConfig['targetClass']); |
38
|
1 |
|
$propertyConfig['properties'] = $nestedClass->accept($this); |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
$classConfig[$property->getName()] = array_merge( |
42
|
1 |
|
$classConfig[$property->getName()], |
43
|
1 |
|
$this->filterPropertyConfig($propertyConfig) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
return $classConfig; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
protected function filterPropertyConfig(array $config): array |
52
|
|
|
{ |
53
|
1 |
|
return $config; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|