示例#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;
 }
 /**
  * @param  string                            $streamUrl
  * @param  EntryEmbedMode                    $embedMode
  * @return StreamFeed
  * @throws Exception\StreamDeletedException
  * @throws Exception\StreamNotFoundException
  */
 private function readStreamFeed($streamUrl, EntryEmbedMode $embedMode = null)
 {
     $request = $this->getJsonRequest($streamUrl);
     if ($embedMode != null && $embedMode != EntryEmbedMode::NONE()) {
         $uri = Uri::withQueryValue($request->getUri(), 'embed', $embedMode->toNative());
         $request = $request->withUri($uri);
     }
     $this->sendRequest($request);
     $this->ensureStatusCodeIsGood($streamUrl);
     return new StreamFeed($this->lastResponseAsJson(), $embedMode);
 }
 /**
  * @test
  */
 public function event_data_is_embedded_with_body_mode()
 {
     $streamName = $this->prepareTestStream();
     $streamFeed = $this->es->openStreamFeed($streamName, EntryEmbedMode::BODY());
     $json = $streamFeed->getJson();
     $this->assertEquals(['foo' => 'bar'], json_decode($json['entries'][0]['data'], true));
 }
 /**
  * @return array
  */
 public static function modeProvider()
 {
     return [[null, EntryEmbedMode::NONE()], [$eem = EntryEmbedMode::NONE(), $eem], [$eem = EntryEmbedMode::RICH(), $eem], [$eem = EntryEmbedMode::BODY(), $eem]];
 }