public static function reconstitute(EventStream $events) { $user = new static($events->aggregateId()); foreach ($events as $event) { $user->apply($event); } return $user; }
public function append(EventStream $events) { foreach ($events as $event) { $data = $this->serializer->serialize($event, 'json'); $event = $this->serializer->serialize(['type' => get_class($event), 'created_on' => (new DateTimeImmutable('now', new DateTimeZone('UTC')))->getTimestamp(), 'data' => $data], 'json'); $this->predis->rpush('events:' . $events->aggregateId(), $event); $this->predis->rpush('published_events', $event); } }