Пример #1
0
 public static function reconstitute(EventStream $eventStream)
 {
     $id = $eventStream->aggregateId();
     $document = new self($id);
     $document->initializeFromEventStream($eventStream);
     return $document;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function appendStream(EventStream $eventStream)
 {
     $id = $eventStream->aggregateId()->toString();
     $type = $eventStream->aggregateType()->toString();
     if (!isset($this->streamData[$type])) {
         $this->streamData[$type] = [];
     }
     if (!isset($this->streamData[$type][$id])) {
         $this->streamData[$type][$id] = new StreamData($id, $type);
     }
     if ($this->streamData[$type][$id]->getVersion() !== $eventStream->committed()) {
         $expected = $eventStream->committed();
         $found = $this->streamData[$type][$id]->getVersion();
         $message = sprintf('Expected v%s; found v%s in stream [%s]{%s}', $expected, $found, $type, $id);
         throw ConcurrencyException::create($message);
     }
     $events = [];
     foreach ($eventStream as $eventMessage) {
         $events[] = new StoredEvent($eventMessage);
     }
     $this->streamData[$type][$id]->addEvents($events);
     $this->streamData[$type][$id]->setVersion($eventStream->version());
 }