Hateoas icon indicating copy to clipboard operation
Hateoas copied to clipboard

Annotation Class Inheritance

Open maennchen opened this issue 9 years ago • 0 comments

It seems that the class inheritance is ignored for annotations.

I need to do that to get the inheritance. Am I doing something wrong?

(It works with the patch below. I'd be happy to contribute a proper PR.)

From 0111785f8fc91e66195916072f1fcff05cbfa95d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonatan=20M=C3=A4nnchen?= <[email protected]>
Date: Thu, 19 May 2016 11:47:25 +0000
Subject: [PATCH] Annotation Class Inheritance

---
 src/Hateoas/Configuration/Metadata/Driver/AnnotationDriver.php | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/Hateoas/Configuration/Metadata/Driver/AnnotationDriver.php b/src/Hateoas/Configuration/Metadata/Driver/AnnotationDriver.php
index 6364c55..41cc53d 100644
--- a/src/Hateoas/Configuration/Metadata/Driver/AnnotationDriver.php
+++ b/src/Hateoas/Configuration/Metadata/Driver/AnnotationDriver.php
@@ -37,6 +37,12 @@ class AnnotationDriver implements DriverInterface
     {
         $annotations = $this->reader->getClassAnnotations($class);

+        $parent = $class->getParentClass();
+        while($parent instanceof  \ReflectionClass) {
+            $annotations = array_merge($annotations, $this->reader->getClassAnnotations($parent));
+            $parent = $parent->getParentClass();
+        }
+
         if (0 === count($annotations)) {
             return null;
         }
--
2.2.1

maennchen avatar May 19 '16 11:05 maennchen