Beispiel #1
0
 /**
  * @inheritDoc
  */
 public function fetchEventsForStream(Stream $stream)
 {
     if (!method_exists($this->connection, 'createQueryBuilder')) {
         throw new \RuntimeException('The provided connection does not support query building, please choose a different connection type ' . 'that does');
     }
     /** @var QueryBuilder $query */
     $query = $this->connection->createQueryBuilder()->select('*')->from($this->options[self::OPTION_TABLENAME])->where('stream_id = :streamId')->orderBy('sequence', 'ASC');
     $query->setParameter('streamId', (string) $stream->id());
     $events = $query->execute();
     $result = [];
     while ($event = $events->fetch()) {
         $result[] = Stream\Event::fromArray(['id' => (string) $event['id'], 'stream' => $stream, 'emitted_at' => $event['emitted_at'], 'payload' => json_decode($event['payload']), 'sequence' => $event['sequence'], 'metadata' => []]);
         $stream->moveHeadTo((int) $event['sequence']);
     }
     return $result;
 }
Beispiel #2
0
 /**
  * Associates a clone of this event with the given stream and assigns it a new sequence number.
  *
  * @param Stream $stream
  *
  * @return Event
  */
 public function withStream(Stream $stream)
 {
     $clone = clone $this;
     $clone->stream = $stream;
     $clone->sequence = $stream->incrementHead();
     return $clone;
 }
Beispiel #3
0
 /**
  * @inheritDoc
  */
 public function fetchEventsForStream(Stream $stream)
 {
     $id = (string) $stream->id();
     return isset($this->events[$id]) ? $this->events[$id] : [];
 }