|
113 | 113 | use Symfony\Component\Messenger\MessageBus; |
114 | 114 | use Symfony\Component\Messenger\MessageBusInterface; |
115 | 115 | use Symfony\Component\Messenger\Middleware\RouterContextMiddleware; |
| 116 | +use Symfony\Component\Messenger\Stamp\SerializedMessageStamp; |
116 | 117 | use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; |
117 | 118 | use Symfony\Component\Messenger\Transport\TransportFactoryInterface; |
118 | 119 | use Symfony\Component\Messenger\Transport\TransportInterface; |
@@ -651,18 +652,30 @@ public function load(array $configs, ContainerBuilder $container) |
651 | 652 | $container->registerAttributeForAutoconfiguration(AsController::class, static function (ChildDefinition $definition, AsController $attribute): void { |
652 | 653 | $definition->addTag('controller.service_arguments'); |
653 | 654 | }); |
654 | | - $container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definition, AsMessageHandler $attribute, \ReflectionClass|\ReflectionMethod $reflector): void { |
655 | | - $tagAttributes = get_object_vars($attribute); |
656 | | - $tagAttributes['from_transport'] = $tagAttributes['fromTransport']; |
657 | | - unset($tagAttributes['fromTransport']); |
658 | | - if ($reflector instanceof \ReflectionMethod) { |
659 | | - if (isset($tagAttributes['method'])) { |
660 | | - throw new LogicException(sprintf('AsMessageHandler attribute cannot declare a method on "%s::%s()".', $reflector->class, $reflector->name)); |
| 655 | + |
| 656 | + if (class_exists(SerializedMessageStamp::class)) { |
| 657 | + // symfony/messenger >= 6.1 |
| 658 | + $container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definition, AsMessageHandler $attribute, \ReflectionClass|\ReflectionMethod $reflector): void { |
| 659 | + $tagAttributes = get_object_vars($attribute); |
| 660 | + $tagAttributes['from_transport'] = $tagAttributes['fromTransport']; |
| 661 | + unset($tagAttributes['fromTransport']); |
| 662 | + if ($reflector instanceof \ReflectionMethod) { |
| 663 | + if (isset($tagAttributes['method'])) { |
| 664 | + throw new LogicException(sprintf('AsMessageHandler attribute cannot declare a method on "%s::%s()".', $reflector->class, $reflector->name)); |
| 665 | + } |
| 666 | + $tagAttributes['method'] = $reflector->getName(); |
661 | 667 | } |
662 | | - $tagAttributes['method'] = $reflector->getName(); |
663 | | - } |
664 | | - $definition->addTag('messenger.message_handler', $tagAttributes); |
665 | | - }); |
| 668 | + $definition->addTag('messenger.message_handler', $tagAttributes); |
| 669 | + }); |
| 670 | + } else { |
| 671 | + // symfony/messenger < 6.1 |
| 672 | + $container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definition, AsMessageHandler $attribute): void { |
| 673 | + $tagAttributes = get_object_vars($attribute); |
| 674 | + $tagAttributes['from_transport'] = $tagAttributes['fromTransport']; |
| 675 | + unset($tagAttributes['fromTransport']); |
| 676 | + $definition->addTag('messenger.message_handler', $tagAttributes); |
| 677 | + }); |
| 678 | + } |
666 | 679 |
|
667 | 680 | if (!$container->getParameter('kernel.debug')) { |
668 | 681 | // remove tagged iterator argument for resource checkers |
|
0 commit comments