Happyr / message-serializer

Serialize messages for transport over the wire
MIT License
77 stars 12 forks source link

Error in documentation that leads into a "failed to transform message" #16

Closed tristanbes closed 5 years ago

tristanbes commented 5 years ago

Hello,

I'm not sure but following the documentation gives me an error Transformer "App\Admin\KeywordBundle\Message\KeywordMessage" failed to transform a message.

Dumping the $message variable in the Transformer.php (on your lib) shows that it's an instance of Envelope; admin_yprox_vm_18905_platform_refresh_default_keyword_all

So it's logic that fails

    public function getPayload($message): array
    {        
        return [
            'keywordId' => $message->getKeywordId(),
            'url'       => $message->getUrl(),
            'callback'  => $message->getCallback(),
        ];
    }

So either I'm missing something, either the documentation is wrong and should add:

    public function getPayload($message): array
    {
        if ($message instanceof Envelope) {
            $message = $message->getMessage();
        }

        return [
            'keywordId' => $message->getKeywordId(),
            'url'       => $message->getUrl(),
            'callback'  => $message->getCallback(),
        ];
    }

(I don't know if the getPayload recieves 100% of the time an Envelope object; so depending on this question, the code could be improved;

Nyholm commented 5 years ago

You are correct. When using the Serializer (with Messanger) you get an envelope. Doing:

        if ($message instanceof Envelope) {
            $message = $message->getMessage();
        }

is what I do too.

Maybe we should update the docs with that and a small comment.