事件负载中的 Prooph 和对象

Prooph and object in event payload

负载中只有标量和数组值的原因是什么?使用具有 toString 或 toArray 方法的对象可以更灵活吗? 我会使用包含完整 ValueObject 或类似事物的事件调度,然后我可以构建 ReadModel 而无需不必要地调用存储库。

是的,它可以更灵活,但您必须针对消息接口实现自己的基本消息:https://github.com/prooph/common/blob/master/docs/messaging.md#custom-messages

prooph的默认消息实现只允许标量和数组的原因也可以在文档中找到:https://github.com/prooph/common/blob/master/docs/messaging.md#payload

Since prooph/common 3.x payload is no longer part of the message object but instead methods are required to get/set the payload. Payload is the data transported by the message. It should only consist of scalar types and sub arrays so that it can easily be json_encoded and json_decoded. Implementers don't need to manage a payload property but public function payload() should return the message data. The protected function setPayload(array $payload) method instead should reconstitute message data from given payload array.

您也可以在 github 上关注有关此主题的讨论:https://github.com/prooph/common/issues/54