@@ 13-29 (lines=17) @@ | ||
10 | use AmaTeam\ElasticSearch\Entity\Entity; |
|
11 | use ReflectionClass; |
|
12 | ||
13 | class ClassParameterAnnotationListener implements ClassAnnotationListenerInterface |
|
14 | { |
|
15 | public function accept(ReflectionClass $class, Entity $entity, $annotation): void |
|
16 | { |
|
17 | if (!($annotation instanceof ParameterAnnotationInterface)) { |
|
18 | return; |
|
19 | } |
|
20 | $mapping = $entity->getMapping(); |
|
21 | $views = [$mapping->getDefaultView()]; |
|
22 | if ($annotation instanceof ViewAwareAnnotationInterface && !empty($annotation->getViews())) { |
|
23 | $views = $mapping->requestViews(...$annotation->getViews()); |
|
24 | } |
|
25 | foreach ($views as $view) { |
|
26 | $view->setParameter($annotation->getParameter(), $annotation->getValue()); |
|
27 | } |
|
28 | } |
|
29 | } |
|
30 |
@@ 13-29 (lines=17) @@ | ||
10 | use AmaTeam\ElasticSearch\Entity\Entity; |
|
11 | use ReflectionProperty; |
|
12 | ||
13 | class PropertyParameterAnnotationListener implements PropertyAnnotationListenerInterface |
|
14 | { |
|
15 | public function accept(ReflectionProperty $property, Entity $entity, $annotation): void |
|
16 | { |
|
17 | if (!($annotation instanceof ParameterAnnotationInterface)) { |
|
18 | return; |
|
19 | } |
|
20 | $mapping = $entity->getMapping()->requestProperty($property->getName()); |
|
21 | $views = [$mapping->getDefaultView()]; |
|
22 | if ($annotation instanceof ViewAwareAnnotationInterface && !empty($annotation->getViews())) { |
|
23 | $views = $mapping->requestViews(...$annotation->getViews()); |
|
24 | } |
|
25 | foreach ($views as $view) { |
|
26 | $view->setParameter($annotation->getParameter(), $annotation->getValue()); |
|
27 | } |
|
28 | } |
|
29 | } |
|
30 |