Ejemplo n.º 1
0
 /**
  * @return JsonModel
  */
 public function getList()
 {
     $previousEventId = $this->params()->fromQuery('previousEventId');
     $count = $this->params()->fromQuery('count', 10);
     if ($previousEventId) {
         $previousEventId = Uuid::fromString($previousEventId);
     }
     $iterator = $this->eventStore->iterate($previousEventId);
     $selfUrl = $this->url()->fromRoute(null, [], ['force_canonical' => true], true);
     $nextUrl = false;
     $lastEventId = $previousEventId;
     $events = [];
     $i = 0;
     /** @var EventMessageInterface $event */
     foreach ($iterator as $event) {
         if ($i >= $count) {
             break;
         }
         $events[] = $event;
         $i++;
         $lastEventId = $event->getId()->toString();
     }
     $nextUrl = $this->url()->fromRoute(null, [], ['force_canonical' => true, 'query' => ['previousEventId' => (string) $lastEventId]], true);
     $data = ['_links' => ['self' => $selfUrl, 'next' => $nextUrl], 'count' => count($events), '_embedded' => ['event' => array_values($events)]];
     return new JsonModel($data);
 }
Ejemplo n.º 2
0
 /**
  * @return Generator
  */
 public function getIterator()
 {
     $eventIterator = $this->eventStore->iterate($this->lastEventId);
     /** @var EventMessageInterface $event */
     foreach ($eventIterator as $event) {
         $this->lastEventId = $event->getId();
         (yield $event);
     }
 }
Ejemplo n.º 3
0
 /**
  * @param null|UuidInterface $previousEventId
  * @return Traversable
  */
 public function iterate(UuidInterface $previousEventId = null)
 {
     return $this->eventStore->iterate($previousEventId);
 }