gargi258
gargi258

Reputation: 839

Prooph and object in event payload

what is reason for only scalar and array values in payload? Can it be more flexible with object which has toString or toArray method? I would use event dispatched which contain complete ValueObject or similar thing, then I can build ReadModel without unnecessary call to repository.

Upvotes: 0

Views: 215

Answers (2)

Sascha-Oliver Prolic
Sascha-Oliver Prolic

Reputation: 91

You can also follow the discussion about this topic on github: https://github.com/prooph/common/issues/54

Upvotes: 1

Alexander Miertsch
Alexander Miertsch

Reputation: 306

yes, it can be more flexible but you have to implement your own basic message against the message interface: https://github.com/prooph/common/blob/master/docs/messaging.md#custom-messages

The reason why prooph's default message implementation only allows scalars and arrays can also be found in the docs: 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.

Upvotes: 2

Related Questions