@@ -40,6 +40,7 @@ public function fromClassReflection(\ReflectionClass $from, bool $withBodies = f
40
40
$ class ->setImplements ($ ifaces );
41
41
42
42
$ class ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
43
+ $ class ->setAttributes (self ::getAttributes ($ from ));
43
44
if ($ from ->getParentClass ()) {
44
45
$ class ->setExtends ($ from ->getParentClass ()->name );
45
46
$ class ->setImplements (array_diff ($ class ->getImplements (), $ from ->getParentClass ()->getInterfaceNames ()));
@@ -99,6 +100,7 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
99
100
$ method ->setReturnReference ($ from ->returnsReference ());
100
101
$ method ->setVariadic ($ from ->isVariadic ());
101
102
$ method ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
103
+ $ method ->setAttributes (self ::getAttributes ($ from ));
102
104
if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
103
105
$ method ->setReturnType ($ from ->getReturnType ()->getName ());
104
106
$ method ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
@@ -117,6 +119,7 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
117
119
if (!$ from ->isClosure ()) {
118
120
$ function ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
119
121
}
122
+ $ function ->setAttributes (self ::getAttributes ($ from ));
120
123
if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
121
124
$ function ->setReturnType ($ from ->getReturnType ()->getName ());
122
125
$ function ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
@@ -150,6 +153,7 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
150
153
: $ from ->getDefaultValue ());
151
154
$ param ->setNullable ($ param ->isNullable () && $ param ->getDefaultValue () !== null );
152
155
}
156
+ $ param ->setAttributes (self ::getAttributes ($ from ));
153
157
return $ param ;
154
158
}
155
159
@@ -164,6 +168,7 @@ public function fromConstantReflection(\ReflectionClassConstant $from): Constant
164
168
: ($ from ->isProtected () ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC )
165
169
);
166
170
$ const ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
171
+ $ const ->setAttributes (self ::getAttributes ($ from ));
167
172
return $ const ;
168
173
}
169
174
@@ -185,6 +190,7 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
185
190
$ prop ->setInitialized (array_key_exists ($ prop ->getName (), $ defaults ));
186
191
}
187
192
$ prop ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
193
+ $ prop ->setAttributes (self ::getAttributes ($ from ));
188
194
return $ prop ;
189
195
}
190
196
@@ -327,4 +333,17 @@ private function parse($from): array
327
333
328
334
return [$ code , $ stmts ];
329
335
}
336
+
337
+
338
+ private function getAttributes ($ from ): array
339
+ {
340
+ if (PHP_VERSION_ID < 80000 ) {
341
+ return [];
342
+ }
343
+ $ res = [];
344
+ foreach ($ from ->getAttributes () as $ attr ) {
345
+ $ res [] = new Attribute ($ attr ->getName (), $ attr ->getArguments ());
346
+ }
347
+ return $ res ;
348
+ }
330
349
}
0 commit comments