|
116 | 116 | use Symfony\Component\Messenger\MessageBus; |
117 | 117 | use Symfony\Component\Messenger\MessageBusInterface; |
118 | 118 | use Symfony\Component\Messenger\Middleware\RouterContextMiddleware; |
| 119 | +use Symfony\Component\Messenger\Stamp\SerializedMessageStamp; |
119 | 120 | use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; |
120 | 121 | use Symfony\Component\Messenger\Transport\TransportFactoryInterface; |
121 | 122 | use Symfony\Component\Messenger\Transport\TransportInterface; |
@@ -664,18 +665,30 @@ public function load(array $configs, ContainerBuilder $container) |
664 | 665 | $container->registerAttributeForAutoconfiguration(AsController::class, static function (ChildDefinition $definition, AsController $attribute): void { |
665 | 666 | $definition->addTag('controller.service_arguments'); |
666 | 667 | }); |
667 | | - $container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definition, AsMessageHandler $attribute, \ReflectionClass|\ReflectionMethod $reflector): void { |
668 | | - $tagAttributes = get_object_vars($attribute); |
669 | | - $tagAttributes['from_transport'] = $tagAttributes['fromTransport']; |
670 | | - unset($tagAttributes['fromTransport']); |
671 | | - if ($reflector instanceof \ReflectionMethod) { |
672 | | - if (isset($tagAttributes['method'])) { |
673 | | - throw new LogicException(sprintf('AsMessageHandler attribute cannot declare a method on "%s::%s()".', $reflector->class, $reflector->name)); |
| 668 | + |
| 669 | + if (class_exists(SerializedMessageStamp::class)) { |
| 670 | + // symfony/messenger >= 6.1 |
| 671 | + $container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definition, AsMessageHandler $attribute, \ReflectionClass|\ReflectionMethod $reflector): void { |
| 672 | + $tagAttributes = get_object_vars($attribute); |
| 673 | + $tagAttributes['from_transport'] = $tagAttributes['fromTransport']; |
| 674 | + unset($tagAttributes['fromTransport']); |
| 675 | + if ($reflector instanceof \ReflectionMethod) { |
| 676 | + if (isset($tagAttributes['method'])) { |
| 677 | + throw new LogicException(sprintf('AsMessageHandler attribute cannot declare a method on "%s::%s()".', $reflector->class, $reflector->name)); |
| 678 | + } |
| 679 | + $tagAttributes['method'] = $reflector->getName(); |
674 | 680 | } |
675 | | - $tagAttributes['method'] = $reflector->getName(); |
676 | | - } |
677 | | - $definition->addTag('messenger.message_handler', $tagAttributes); |
678 | | - }); |
| 681 | + $definition->addTag('messenger.message_handler', $tagAttributes); |
| 682 | + }); |
| 683 | + } else { |
| 684 | + // symfony/messenger < 6.1 |
| 685 | + $container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definition, AsMessageHandler $attribute): void { |
| 686 | + $tagAttributes = get_object_vars($attribute); |
| 687 | + $tagAttributes['from_transport'] = $tagAttributes['fromTransport']; |
| 688 | + unset($tagAttributes['fromTransport']); |
| 689 | + $definition->addTag('messenger.message_handler', $tagAttributes); |
| 690 | + }); |
| 691 | + } |
679 | 692 |
|
680 | 693 | if (!$container->getParameter('kernel.debug')) { |
681 | 694 | // remove tagged iterator argument for resource checkers |
|
0 commit comments