I get the full annotation classname as result (and this is right). So it seems, that the framework recognizes the annotation but only getMethodsAnnotatedWith() doesn’t work!?
The ReflectionService should generally not be used for Production use. You might want to use the CompileStatic annotation and functionality to render the list of annotated methods during compilation of proxies. That should work just fine and avoid using the reflection service in production.
I had exactly the same problem and I noticed that the ReflectionService does not cache the array classesByMethodAnnotations. I was able to solve this using CompileStatic.
Here is another example saving all methods annotated with a specific annotation (in this case CallbackTransformer) in an array:
class SomeService
{
/**
* @Flow\Inject
* @var ObjectManagerInterface
*/
protected $objectManager;
protected $callbackTransformMethods = [];
public function initializeObject()
{
$this->callbackTransformMethods = static::initializeCallbackTransformMethods($this->objectManager);
}
public function addIndexableClassProperties($object, ?array $data): ?array
{
if ($data === null) {
$data = [];
}
$className = TypeHandling::getTypeForValue($object);
if (isset($this->callbackTransformMethods[$className])) {
foreach($this->callbackTransformMethods[$className] as $method) {
$data = array_merge($data, $object->$method($data));
}
}
return $data;
}
/**
* @Flow\CompileStatic
* @param ObjectManagerInterface $objectManager
*/
protected static function initializeCallbackTransformMethods($objectManager): array
{
$methods = [];
$reflectionService = $objectManager->get(ReflectionService::class);
$classNames = $reflectionService->getClassesContainingMethodsAnnotatedWith(CallbackTransform::class);
foreach($classNames as $className) {
$methods[$className] = $reflectionService->getMethodsAnnotatedWith($className, CallbackTransform::class);
}
return $methods;
}
}