8
8
use Doctrine \Common \Annotations \Reader ;
9
9
use EmagTechLabs \AnnotationCacheBundle \Annotation \Cache ;
10
10
use EmagTechLabs \AnnotationCacheBundle \ProxyManager \CacheFactory ;
11
+ use ReflectionAttribute ;
11
12
use ReflectionClass ;
12
13
use ReflectionException ;
13
14
use ReflectionMethod ;
@@ -113,7 +114,10 @@ private function setCachedDefinitions(Definition $definition, ContainerBuilder $
113
114
$ originalReflection = new ReflectionClass ($ definition ->getClass ());
114
115
115
116
foreach ($ originalReflection ->getMethods () as $ method ) {
116
- if ($ annotationReader ->getMethodAnnotation ($ method , Cache::class)) {
117
+ if (
118
+ $ this ->getMethodAttributes ($ method , Cache::class) ||
119
+ $ annotationReader ->getMethodAnnotation ($ method , Cache::class)
120
+ ) {
117
121
$ this ->validateMethod ($ method );
118
122
119
123
$ wrapper = (new Definition ($ definition ->getClass ()))
@@ -133,6 +137,23 @@ private function setCachedDefinitions(Definition $definition, ContainerBuilder $
133
137
}
134
138
}
135
139
140
+ /**
141
+ * @param ReflectionMethod $method
142
+ * @param string $annotationName
143
+ */
144
+ private function getMethodAttributes (ReflectionMethod $ method , string $ annotationName ): ?ReflectionAttribute
145
+ {
146
+ if (PHP_VERSION_ID >= 80000 ) {
147
+ $ attributes = $ method ->getAttributes ($ annotationName , ReflectionAttribute::IS_INSTANCEOF );
148
+
149
+ foreach ($ attributes as $ attribute ) {
150
+ return $ attribute ;
151
+ }
152
+ }
153
+
154
+ return null ;
155
+ }
156
+
136
157
/**
137
158
* @param ReflectionMethod $method
138
159
*/
0 commit comments