streak icon indicating copy to clipboard operation
streak copied to clipboard

make snapshotting easier with event sourcing aggregate trait

Open alanbem opened this issue 6 years ago • 0 comments

Now you have to add internal state of event sourcing aggregate trait manually e.g.

    use Streak\Domain\Event\Sourcing;

    public function fromMemento(array $memento)
    {

        $this->accounts = $memento['accounts'];
 
       // event sourced aggregate trait deserialization below
        $this->events = $memento['events'];
        $this->lastEvent = $memento['last_event'];
        $this->replaying = $memento['replaying'];
        $this->lastReplayed = $memento['last_replayed'];
        $this->version = $memento['version'];
    }

    public function toMemento() : array
    {
        $memento = [

            'accounts' => $this->accounts,

            // event sourced aggregate trait serialization below
            'events' => $this->events,
            'last_event' => $this->lastEvent,
            'replaying' => $this->replaying,
            'last_replayed' => $this->lastReplayed,
            'version' => $this->version,
        ];

        return $memento;
    }

find a way to make it easier, more automatic, even transparent to developer.

alanbem avatar Jul 21 '19 08:07 alanbem