Skip to content

Commit b41166f

Browse files
committed
Add possibility to use arbitrary Annotations on methods
1 parent c1e8b8f commit b41166f

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/Drivers/EloquentEntitySet.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Flat3\Lodata\Helper\JSON;
3434
use Flat3\Lodata\Helper\PropertyValue;
3535
use Flat3\Lodata\Helper\PropertyValues;
36+
use Flat3\Lodata\Interfaces\AnnotationFactoryInterface;
3637
use Flat3\Lodata\Interfaces\EntitySet\ComputeInterface;
3738
use Flat3\Lodata\Interfaces\EntitySet\CountInterface;
3839
use Flat3\Lodata\Interfaces\EntitySet\CreateInterface;
@@ -866,29 +867,27 @@ public function discover(): self
866867
}
867868

868869
/** @var ReflectionMethod $reflectionMethod */
869-
foreach (Discovery::getReflectedMethods($this->model) as $reflectionMethod) {
870-
/** @var LodataRelationship $relationshipInstance */
871-
$relationshipInstance = Discovery::getFirstMethodAttributeInstance(
872-
$reflectionMethod,
873-
LodataRelationship::class
874-
);
875-
876-
if (!$relationshipInstance) {
877-
continue;
878-
}
879-
880-
$relationshipMethod = $reflectionMethod->getName();
881-
882-
try {
883-
$this->discoverRelationship(
884-
$relationshipMethod,
885-
$relationshipInstance->getName(),
886-
$relationshipInstance->getDescription(),
887-
$relationshipInstance->isNullable()
888-
);
889-
} catch (ConfigurationException $e) {
870+
foreach (Discovery::getReflectedMethods($this->model) as $reflectionMethod)
871+
foreach ($reflectionMethod->getAttributes() as $attribute) {
872+
873+
$instance = $attribute->newInstance();
874+
if ($instance instanceof LodataRelationship) {
875+
$relationshipMethod = $reflectionMethod->getName();
876+
877+
try {
878+
$this->discoverRelationship(
879+
$relationshipMethod,
880+
$instance->getName(),
881+
$instance->getDescription(),
882+
$instance->isNullable()
883+
);
884+
} catch (ConfigurationException $e) {
885+
}
886+
}
887+
else if ($instance instanceof AnnotationFactoryInterface) {
888+
$this->addAnnotation($instance->toAnnotation());
889+
}
890890
}
891-
}
892891

893892
return $this;
894893
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Flat3\Lodata\Interfaces;
4+
5+
use Flat3\Lodata\Annotation;
6+
7+
interface AnnotationFactoryInterface
8+
{
9+
/**
10+
* Gibt eine Annotation-Instanz zurück, die dieses Attribut repräsentiert.
11+
*/
12+
public function toAnnotation(): Annotation;
13+
}

0 commit comments

Comments
 (0)