Skip to content

Commit afe118e

Browse files
committed
Fix issue when CacheCompilerPass would not overwrite definition when Cache was used as Attribute
1 parent 048373e commit afe118e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/DependencyInjection/Compiler/CacheCompilerPass.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\Common\Annotations\Reader;
99
use EmagTechLabs\AnnotationCacheBundle\Annotation\Cache;
1010
use EmagTechLabs\AnnotationCacheBundle\ProxyManager\CacheFactory;
11+
use ReflectionAttribute;
1112
use ReflectionClass;
1213
use ReflectionException;
1314
use ReflectionMethod;
@@ -113,7 +114,10 @@ private function setCachedDefinitions(Definition $definition, ContainerBuilder $
113114
$originalReflection = new ReflectionClass($definition->getClass());
114115

115116
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+
) {
117121
$this->validateMethod($method);
118122

119123
$wrapper = (new Definition($definition->getClass()))
@@ -133,6 +137,23 @@ private function setCachedDefinitions(Definition $definition, ContainerBuilder $
133137
}
134138
}
135139

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+
136157
/**
137158
* @param ReflectionMethod $method
138159
*/

0 commit comments

Comments
 (0)