@@ -12,7 +12,7 @@ trait ReflectionCacheTrait
1212{
1313 private array $ classReflectionCache = [];
1414
15- private function getClassReflection (string $ className ): ?ReflectionClass
15+ private function getClassReflection (string $ className, bool $ recursive = false ): ?ReflectionClass
1616 {
1717 $ cacheKey = \md5 ($ className );
1818
@@ -24,9 +24,43 @@ private function getClassReflection(string $className): ?ReflectionClass
2424 }
2525 }
2626
27+ if (
28+ true === $ recursive
29+ && false !== $ this ->classReflectionCache [$ cacheKey ]->getParentClass ()
30+ && false === \array_key_exists ($ cacheKey , $ this ->classReflectionCache )
31+ ) {
32+ $ this ->getClassReflection ($ this ->classReflectionCache [$ cacheKey ]->getParentClass ());
33+ }
34+
2735 return $ this ->classReflectionCache [$ cacheKey ] ?? null ;
2836 }
2937
38+ /**
39+ * @return ReflectionProperty[]
40+ */
41+ public function getPropertyReflections (string $ className , bool $ recursive = false , int $ filter = null ): array
42+ {
43+ $ classReflection = $ this ->getClassReflection ($ className , $ recursive );
44+
45+ $ properties = $ classReflection ->getProperties ();
46+
47+ if (false !== $ classReflection ->getParentClass () && true === $ recursive ) {
48+ $ parentProperties = $ this ->getPropertyReflections ($ classReflection ->getParentClass ()->getName (), $ recursive , $ filter );
49+
50+ $ filtered = \array_filter ($ parentProperties , function (ReflectionProperty $ parentProperty ) use ($ properties ) {
51+ $ childDefinition = \array_filter ($ properties , function (ReflectionProperty $ childProperty ) use ($ parentProperty ) {
52+ return $ childProperty ->getName () === $ parentProperty ->getName ()
53+ && $ childProperty ->getDeclaringClass ()->getName () === $ parentProperty ->getDeclaringClass ()->getName ();
54+ });
55+ return \count ($ childDefinition ) === 0 ;
56+ });
57+
58+ $ properties = \array_merge ($ filtered , $ properties );
59+ }
60+
61+ return $ properties ;
62+ }
63+
3064 public function getMethodReflection (string $ className , string $ methodName ): ?ReflectionMethod
3165 {
3266 $ rc = $ this ->getClassReflection ($ className );
0 commit comments