Allow multiple "AsMessageHandler" attributes
This commit is contained in:
parent
dc00f8b7d6
commit
df4d3b5fa9
1 changed files with 19 additions and 16 deletions
|
@ -54,23 +54,26 @@ class HandlersLocatorFactory
|
||||||
$asHandlerClasses = $this->reflectionService
|
$asHandlerClasses = $this->reflectionService
|
||||||
->getClassNamesByAnnotation(AsMessageHandler::class);
|
->getClassNamesByAnnotation(AsMessageHandler::class);
|
||||||
foreach ($asHandlerClasses as $asHandlerClass) {
|
foreach ($asHandlerClasses as $asHandlerClass) {
|
||||||
/** @var AsMessageHandler $annotation */
|
/** @var AsMessageHandler[] $annotations */
|
||||||
$annotation = $this->reflectionService->getClassAnnotation($asHandlerClass, AsMessageHandler::class);
|
$annotations = $this->reflectionService->getClassAnnotations($asHandlerClass, AsMessageHandler::class);
|
||||||
$config['from_transport'] = $annotation->fromTransport;
|
foreach ($annotations as $annotation) {
|
||||||
$config['priority'] = $annotation->priority;
|
$config['from_transport'] = $annotation->fromTransport;
|
||||||
$method = $annotation->method ?? '__invoke';
|
$config['priority'] = $annotation->priority;
|
||||||
$messageName = $annotation->handles;
|
$method = $annotation->method ?? '__invoke';
|
||||||
if ($messageName === null) {
|
$messageName = $annotation->handles;
|
||||||
$arguments = $this->reflectionService->getMethodParameters($asHandlerClass, $method);
|
if ($messageName === null) {
|
||||||
$messageName = $arguments[\array_key_first($arguments)]['class'];
|
$arguments = $this->reflectionService->getMethodParameters($asHandlerClass, $method);
|
||||||
|
$messageName = $arguments[\array_key_first($arguments)]['class'];
|
||||||
|
}
|
||||||
|
if ($annotation->bus !== null && $annotation->bus !== $busName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$handler = $this->objectManager->get($asHandlerClass);
|
||||||
|
$handlerDescriptors[$messageName][] = new HandlerDescriptor(
|
||||||
|
$this->objectManager->get($asHandlerClass),
|
||||||
|
$config
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if ($annotation->bus !== null && $annotation->bus !== $busName) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$handlerDescriptors[$messageName][] = new HandlerDescriptor(
|
|
||||||
$this->objectManager->get($asHandlerClass),
|
|
||||||
$config
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// TODO: Maybe we can allow handlers to be added to bus or globally by configuration?
|
// TODO: Maybe we can allow handlers to be added to bus or globally by configuration?
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue