10000 Envelope in symfony/messenger supports only PHP serializable objects · Issue #28164 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Envelope in symfony/messenger supports only PHP serializable objects #28164
Closed
@covobo

Description

@covobo

Description
Why does symfony/messenger/Envelope.php (https://github.com/symfony/messenger/blob/master/Envelope.php) support only complex types (classes)? Look at 34 line there is get_class method which makes impossible to use primitive types (like string or boolean).
It's a problem because symfony doesn't support any other header data (it parses only X-Message-Envelope-Items header). How do I share header information between a few microservices?

Example

If we really want to support only EnvelopeItemInterface items, it's still easy to implement primitives.

There is example:

public function __construct($message, array $items = array())
{
        $this->message = $message;
        foreach ($items as $item) {
            if (!is_object($item)) {
                      switch (detect_type($item)) {
                              case TYPE_BOOLEAN:
                                       $item = new EnvelopeItemBoolean($item);
                              break;
                              case TYPE_STRING:
                                       $item = new EnvelopeItemString($item);
                              break;
                             // ..array, int, null
                      }
            }
            $this->items[\get_class($item)] = $item;
        }
 }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0