@@ -50,7 +50,15 @@ public function read(\ReflectionClass $reflection, string $method): array
5050 */
5151 public function getParamsFromMethod (\ReflectionMethod $ method ): array
5252 {
53- $ annotations = $ this ->annotationReader ->getMethodAnnotations ($ method );
53+ $ annotations = [];
54+ if (\PHP_VERSION_ID >= 80000 ) {
55+ $ annotations = $ this ->getParamsFromAttributes ($ method );
56+ }
57+
58+ $ annotations = array_merge (
59+ $ annotations ,
60+ $ this ->annotationReader ->getMethodAnnotations ($ method ) ?? []
61+ );
5462
5563 return $ this ->getParamsFromAnnotationArray ($ annotations );
5664 }
@@ -60,7 +68,15 @@ public function getParamsFromMethod(\ReflectionMethod $method): array
6068 */
6169 public function getParamsFromClass (\ReflectionClass $ class ): array
6270 {
63- $ annotations = $ this ->annotationReader ->getClassAnnotations ($ class );
71+ $ annotations = [];
72+ if (\PHP_VERSION_ID >= 80000 ) {
73+ $ annotations = $ this ->getParamsFromAttributes ($ class );
74+ }
75+
76+ $ annotations = array_merge (
77+ $ annotations ,
78+ $ this ->annotationReader ->getClassAnnotations ($ class ) ?? []
79+ );
6480
6581 return $ this ->getParamsFromAnnotationArray ($ annotations );
6682 }
@@ -79,4 +95,20 @@ private function getParamsFromAnnotationArray(array $annotations): array
7995
8096 return $ params ;
8197 }
98+
99+ /**
100+ * @param \ReflectionClass|\ReflectionMethod $reflection
101+ *
102+ * @return ParamInterface[]
103+ */
104+ private function getParamsFromAttributes ($ reflection ): array
105+ {
106+ $ params = [];
107+ foreach ($ reflection ->getAttributes (ParamInterface::class, \ReflectionAttribute::IS_INSTANCEOF ) as $ attribute ) {
108+ $ param = $ attribute ->newInstance ();
109+ $ params [$ param ->getName ()] = $ param ;
110+ }
111+
112+ return $ params ;
113+ }
82114}
0 commit comments