Skip to content

Commit 5ac8c55

Browse files
committed
Add possibility to use arbitrary Annotations on methods
1 parent a21abfe commit 5ac8c55

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
@@ -32,6 +32,7 @@
3232
use Flat3\Lodata\Helper\JSON;
3333
use Flat3\Lodata\Helper\PropertyValue;
3434
use Flat3\Lodata\Helper\PropertyValues;
35+
use Flat3\Lodata\Interfaces\AnnotationFactoryInterface;
3536
use Flat3\Lodata\Interfaces\EntitySet\ComputeInterface;
3637
use Flat3\Lodata\Interfaces\EntitySet\CountInterface;
3738
use Flat3\Lodata\Interfaces\EntitySet\CreateInterface;
@@ -787,29 +788,27 @@ public function discover(): self
787788
}
788789

789790
/** @var ReflectionMethod $reflectionMethod */
790-
foreach (Discovery::getReflectedMethods($this->model) as $reflectionMethod) {
791-
/** @var LodataRelationship $relationshipInstance */
792-
$relationshipInstance = Discovery::getFirstMethodAttributeInstance(
793-
$reflectionMethod,
794-
LodataRelationship::class
795-
);
796-
797-
if (!$relationshipInstance) {
798-
continue;
799-
}
800-
801-
$relationshipMethod = $reflectionMethod->getName();
802-
803-
try {
804-
$this->discoverRelationship(
805-
$relationshipMethod,
806-
$relationshipInstance->getName(),
807-
$relationshipInstance->getDescription(),
808-
$relationshipInstance->isNullable()
809-
);
810-
} catch (ConfigurationException $e) {
791+
foreach (Discovery::getReflectedMethods($this->model) as $reflectionMethod)
792+
foreach ($reflectionMethod->getAttributes() as $attribute) {
793+
794+
$instance = $attribute->newInstance();
795+
if ($instance instanceof LodataRelationship) {
796+
$relationshipMethod = $reflectionMethod->getName();
797+
798+
try {
799+
$this->discoverRelationship(
800+
$relationshipMethod,
801+
$instance->getName(),
802+
$instance->getDescription(),
803+
$instance->isNullable()
804+
);
805+
} catch (ConfigurationException $e) {
806+
}
807+
}
808+
else if ($instance instanceof AnnotationFactoryInterface) {
809+
$this->addAnnotation($instance->toAnnotation());
810+
}
811811
}
812-
}
813812

814813
return $this;
815814
}
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)