Exemplo n.º 1
0
 /**
  * @todo lazy loading
  *
  * @param string $eventStream
  * @return DomainEvent[]
  * @throws EventStreamNotFoundException
  */
 public function load($eventStream)
 {
     try {
         $feed = $this->eventStore->openStreamFeed($eventStream, EntryEmbedMode::RICH());
     } catch (StreamNotFoundException $e) {
         throw new EventStreamNotFoundException($e->getMessage(), 1427104251);
     }
     if ($feed->hasLink(LinkRelation::LAST())) {
         $feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::LAST());
     } else {
         $feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::FIRST());
     }
     $rel = LinkRelation::PREVIOUS();
     $domainEvents = [];
     while ($feed !== NULL) {
         /** @var Entry[] $entries */
         $entries = array_reverse($feed->getEntries());
         foreach ($entries as $entry) {
             $event = $this->eventStore->readEvent($entry->getEventUrl());
             if ($event === NULL) {
                 continue;
             }
             $domainEvent = $this->eventTranslator->fromEvent($event, $entry->getType());
             $domainEvent->version = $entry->getVersion();
             $domainEvents[] = $domainEvent;
         }
         $feed = $this->eventStore->navigateStreamFeed($feed, $rel);
     }
     return $domainEvents;
 }
 /**
  * @inheritDoc
  */
 public function load($id)
 {
     try {
         $feed = $this->eventStore->openStreamFeed($id);
     } catch (StreamNotFoundException $e) {
         throw new EventStreamNotFoundException($e->getMessage());
     }
     if ($feed->hasLink(LinkRelation::LAST())) {
         $feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::LAST());
     } else {
         $feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::FIRST());
     }
     $rel = LinkRelation::PREVIOUS();
     $messages = [];
     $i = 0;
     while ($feed !== null) {
         foreach ($this->sortEntries($feed->getEntries()) as $entry) {
             $event = $this->eventStore->readEvent($entry->getEventUrl());
             $data = $event->getData();
             $recordedOn = DateTime::fromString($data['broadway_recorded_on']);
             unset($data['broadway_recorded_on']);
             $messages[] = new DomainMessage($id, $event->getVersion(), new Metadata($event->getMetadata() ?: []), call_user_func([$event->getType(), 'deserialize'], $data), $recordedOn);
         }
         $feed = $this->eventStore->navigateStreamFeed($feed, $rel);
     }
     return new DomainEventStream($messages);
 }
 public static function forward(EventStoreInterface $eventStore, $streamName)
 {
     return new self($eventStore, $streamName, LinkRelation::LAST(), LinkRelation::PREVIOUS(), 'array_reverse');
 }
 public static function relationProvider()
 {
     return [[LinkRelation::FIRST()], [LinkRelation::LAST()]];
 }