예제 #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;
 }
 /**
  * @param $event
  */
 private function applyEventOnProjection(Stream\Event $event)
 {
     if (isset($this->actions[$event->metadata()['type']])) {
         $this->projection = $this->actions[$event->metadata()['type']]($this->projection, $event);
         $this->lastIndex++;
     }
 }