示例#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;
 }
 /**
  * @test
  */
 public function navigate_stream_using_missing_link_returns_null()
 {
     $streamName = $this->prepareTestStream(1);
     $head = $this->es->openStreamFeed($streamName);
     $next = $this->es->navigateStreamFeed($head, LinkRelation::NEXT());
     $this->assertNull($next);
 }