Repository: symfony/symfony
File: src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php (PHP)

Code before:
        $container->getDefinition($busId)->replaceArgument(0, new IteratorArgument(array_values($middlewareReferences)));
    }

    private function getServiceClass(ContainerBuilder $container, string $serviceId): string
    {
        while (true) {
            $definition = $container->findDefinition($serviceId);

            if (!$definition->getClass() && $definition instanceof ChildDefinition) {
                $serviceId = $definition->getParent();

                continue;
            }

            return $definition->getClass();
        }
    }

    private function registerTypeMapping(ContainerBuilder $container): void
    {
        if (!$container->hasDefinition('messenger.transport.symfony_serializer')) {
            return;
        }

        $serializedTypeNameMap = [];
        foreach ($container->findTaggedResourceIds('messenger.message') as $class => $tags) {
            foreach ($tags as $tag) {
                if (isset($tag['serializedTypeName'])) {
                    if (isset($serializedTypeNameMap[$tag['serializedTypeName']])) {
                        throw new RuntimeException(\sprintf('The serialized type "%s" is already mapped to class "%s", cannot map it to "%s" as well. Each serialized type must be unique.', $tag['serializedTypeName'], $serializedTypeNameMap[$tag['serializedTypeName']], $class));
                    }
                    $serializedTypeNameMap[$tag['serializedTypeName']] = $class;
                }
            }
        }

        $container->getDefinition('messenger.transport.symfony_serializer')->replaceArgument(3, $serializedTypeNameMap);
    }
}


Review comment (bug):
this is broken. Keys in this array are service ids, not class names. You must not assume that the class name is used as service id.

Code after:
        $container->getDefinition($busId)->replaceArgument(0, new IteratorArgument(array_values($middlewareReferences)));
    }

    private function getServiceClass(ContainerBuilder $container, string $serviceId): string
    {
        while (true) {
            $definition = $container->findDefinition($serviceId);

            if (!$definition->getClass() && $definition instanceof ChildDefinition) {
                $serviceId = $definition->getParent();

                continue;
            }

            return $definition->getClass();
        }
    }

    private function registerTypeMapping(ContainerBuilder $container): void
    {
        if (!$container->hasDefinition('messenger.transport.symfony_serializer')) {
            return;
        }

        $typeToClassMap = [];
        foreach ($container->findTaggedResourceIds('messenger.message') as $id => $tags) {
            $class = $container->getDefinition($id)->getClass();
            foreach ($tags as $tag) {
                if (!isset($tag['serializedTypeName'])) {
                    continue;
                }
                if (isset($typeToClassMap[$tag['serializedTypeName']])) {
                    throw new RuntimeException(\sprintf('The serialized type name "%s" is already mapped to class "%s", cannot map it to "%s" as well. Each serialized type must be unique.', $tag['serializedTypeName'], $typeToClassMap[$tag['serializedTypeName']], $class));
                }
                $typeToClassMap[$tag['serializedTypeName']] = $class;
            }
        }

        $container->getDefinition('messenger.transport.symfony_serializer')->setArgument(3, $typeToClassMap);
    }
}