Esempio n. 1
0
 /**
  * @param EventStreamId $eventStreamId
  * @return EventStream
  * @throws EventStreamNotFoundException
  * @throws EventSourcingException
  */
 public function eventStreamSince(EventStreamId $eventStreamId)
 {
     try {
         $statement = $this->connection->prepare(sprintf('SELECT stream_version, event_type, event_body FROM %s ' . 'WHERE stream_name = :stream_name AND stream_version >= :stream_version ' . 'ORDER BY stream_version', $this->tableName));
         $statement->bindValue(':stream_name', $eventStreamId->streamName(), PDO::PARAM_STR);
         $statement->bindValue(':stream_version', $eventStreamId->streamVersion(), PDO::PARAM_INT);
         $statement->execute();
         if ($statement->rowCount() === 0) {
             throw EventStreamNotFoundException::noStream($eventStreamId);
         }
         $eventStream = $this->buildEventStream($statement);
         return $eventStream;
     } catch (EventStreamNotFoundException $e) {
         throw $e;
         // escalation
     } catch (Exception $because) {
         throw EventSourcingException::cannotQueryEventStream($eventStreamId, $because);
     }
 }
 /**
  * @param EventStreamId $eventStreamId
  * @param Exception $because
  * @return EventSourcingException
  */
 public static function cannotQueryEventStream(EventStreamId $eventStreamId, Exception $because)
 {
     return new self(sprintf('Cannot query event stream for: %s since version: %s because: %s', $eventStreamId->streamName(), $eventStreamId->streamVersion(), $because->getMessage()), null, $because);
 }
 /**
  * @param EventStreamId $eventStreamId
  * @return EventStreamNotFoundException
  */
 public static function noStream(EventStreamId $eventStreamId)
 {
     return new self(sprintf('There is no such event stream: %s : %s', $eventStreamId->streamName(), $eventStreamId->streamVersion()));
 }