@@ -105,6 +105,16 @@ public static function castType(\ReflectionType $c, array $a, Stub $stub, bool $
105105 return $ a ;
106106 }
107107
108+ public static function castAttribute (\ReflectionAttribute $ c , array $ a , Stub $ stub , bool $ isNested )
109+ {
110+ self ::addMap ($ a , $ c , [
111+ 'name ' => 'getName ' ,
112+ 'arguments ' => 'getArguments ' ,
113+ ]);
114+
115+ return $ a ;
116+ }
117+
108118 public static function castReflectionGenerator (\ReflectionGenerator $ c , array $ a , Stub $ stub , bool $ isNested )
109119 {
110120 $ prefix = Caster::PREFIX_VIRTUAL ;
@@ -151,7 +161,7 @@ public static function castClass(\ReflectionClass $c, array $a, Stub $stub, bool
151161 self ::addMap ($ a , $ c , [
152162 'extends ' => 'getParentClass ' ,
153163 'implements ' => 'getInterfaceNames ' ,
154- 'constants ' => 'getConstants ' ,
164+ 'constants ' => 'getReflectionConstants ' ,
155165 ]);
156166
157167 foreach ($ c ->getProperties () as $ n ) {
@@ -162,6 +172,8 @@ public static function castClass(\ReflectionClass $c, array $a, Stub $stub, bool
162172 $ a [$ prefix .'methods ' ][$ n ->name ] = $ n ;
163173 }
164174
175+ self ::addAttributes ($ a , $ c , $ prefix );
176+
165177 if (!($ filter & Caster::EXCLUDE_VERBOSE ) && !$ isNested ) {
166178 self ::addExtra ($ a , $ c );
167179 }
@@ -206,6 +218,8 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
206218 $ a [$ prefix .'parameters ' ] = new EnumStub ($ a [$ prefix .'parameters ' ]);
207219 }
208220
221+ self ::addAttributes ($ a , $ c , $ prefix );
222+
209223 if (!($ filter & Caster::EXCLUDE_VERBOSE ) && $ v = $ c ->getStaticVariables ()) {
210224 foreach ($ v as $ k => &$ v ) {
211225 if (\is_object ($ v )) {
@@ -225,6 +239,16 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
225239 return $ a ;
226240 }
227241
242+ public static function castClassConstant (\ReflectionClassConstant $ c , array $ a , Stub $ stub , bool $ isNested )
243+ {
244+ $ a [Caster::PREFIX_VIRTUAL .'modifiers ' ] = implode (' ' , \Reflection::getModifierNames ($ c ->getModifiers ()));
245+ $ a [Caster::PREFIX_VIRTUAL .'value ' ] = $ c ->getValue ();
246+
247+ self ::addAttributes ($ a , $ c );
248+
249+ return $ a ;
250+ }
251+
228252 public static function castMethod (\ReflectionMethod $ c , array $ a , Stub $ stub , bool $ isNested )
229253 {
230254 $ a [Caster::PREFIX_VIRTUAL .'modifiers ' ] = implode (' ' , \Reflection::getModifierNames ($ c ->getModifiers ()));
@@ -243,6 +267,8 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
243267 'allowsNull ' => 'allowsNull ' ,
244268 ]);
245269
270+ self ::addAttributes ($ a , $ c , $ prefix );
271+
246272 if ($ v = $ c ->getType ()) {
247273 $ a [$ prefix .'typeHint ' ] = $ v instanceof \ReflectionNamedType ? $ v ->getName () : (string ) $ v ;
248274 }
@@ -271,6 +297,8 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
271297 public static function castProperty (\ReflectionProperty $ c , array $ a , Stub $ stub , bool $ isNested )
272298 {
273299 $ a [Caster::PREFIX_VIRTUAL .'modifiers ' ] = implode (' ' , \Reflection::getModifierNames ($ c ->getModifiers ()));
300+
301+ self ::addAttributes ($ a , $ c );
274302 self ::addExtra ($ a , $ c );
275303
276304 return $ a ;
@@ -377,7 +405,7 @@ private static function addExtra(array &$a, \Reflector $c)
377405 }
378406 }
379407
380- private static function addMap (array &$ a , \ Reflector $ c , array $ map , string $ prefix = Caster::PREFIX_VIRTUAL )
408+ private static function addMap (array &$ a , object $ c , array $ map , string $ prefix = Caster::PREFIX_VIRTUAL )
381409 {
382410 foreach ($ map as $ k => $ m ) {
383411 if (\PHP_VERSION_ID >= 80000 && 'isDisabled ' === $ k ) {
@@ -389,4 +417,13 @@ private static function addMap(array &$a, \Reflector $c, array $map, string $pre
389417 }
390418 }
391419 }
420+
421+ private static function addAttributes (array &$ a , \Reflector $ c , string $ prefix = Caster::PREFIX_VIRTUAL ): void
422+ {
423+ if (\PHP_VERSION_ID >= 80000 ) {
424+ foreach ($ c ->getAttributes () as $ n ) {
425+ $ a [$ prefix .'attributes ' ][] = $ n ;
426+ }
427+ }
428+ }
392429}
0 commit comments