Skip to content

Commit 86ef7ee

Browse files
mjpvandenbergfabpot
authored andcommitted
[Messenger] Allow AsMessageHandler attribute on methods
1 parent 7c50fc6 commit 86ef7ee

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,16 @@ public function load(array $configs, ContainerBuilder $container)
622622
$container->registerAttributeForAutoconfiguration(AsController::class, static function (ChildDefinition $definition, AsController $attribute): void {
623623
$definition->addTag('controller.service_arguments');
624624
});
625-
$container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definition, AsMessageHandler $attribute): void {
625+
$container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definition, AsMessageHandler $attribute, \ReflectionClass|\ReflectionMethod $reflector): void {
626626
$tagAttributes = get_object_vars($attribute);
627627
$tagAttributes['from_transport'] = $tagAttributes['fromTransport'];
628628
unset($tagAttributes['fromTransport']);
629-
629+
if ($reflector instanceof \ReflectionMethod) {
630+
if (isset($tagAttributes['method'])) {
631+
throw new LogicException(sprintf('AsMessageHandler attribute cannot declare a method on "%s::%s()".', $reflector->class, $reflector->name));
632+
}
633+
$tagAttributes['method'] = $reflector->getName();
634+
}
630635
$definition->addTag('messenger.message_handler', $tagAttributes);
631636
});
632637

0 commit comments

Comments
 (0)