Author: Alexander Miertsch (contact@prooph.de)
コード例 #1
0
ファイル: InMemoryAdapter.php プロジェクト: ad3n/event-store
 /**
  * @param StreamName $streamName
  * @param array $metadata
  * @param null|int $minVersion
  * @throws StreamNotFoundException
  * @return Message[]
  */
 public function loadEventsByMetadataFrom(StreamName $streamName, array $metadata, $minVersion = null)
 {
     $streamEvents = [];
     if (!isset($this->streams[$streamName->toString()])) {
         return [];
     }
     foreach ($this->streams[$streamName->toString()] as $index => $streamEvent) {
         if ($this->matchMetadataWith($streamEvent, $metadata)) {
             if (is_null($minVersion) || $streamEvent->version() >= $minVersion) {
                 $streamEvents[] = $streamEvent;
             }
         }
     }
     return $streamEvents;
 }
 /**
  * @param StreamName $streamName
  *
  * @return Repository
  */
 private function getRepositoryForStream(StreamName $streamName)
 {
     return new Repository($streamName->toString(), new Config($this->rootDir));
 }
コード例 #3
0
 /**
  * Get table name for given stream name
  *
  * @param StreamName $streamName
  * @return string
  */
 protected function getTable(StreamName $streamName)
 {
     if (isset($this->streamTableMap[$streamName->toString()])) {
         $tableName = $this->streamTableMap[$streamName->toString()];
     } else {
         $tableName = strtolower($this->getShortStreamName($streamName));
         if (strpos($tableName, "_stream") === false) {
             $tableName .= "_stream";
         }
     }
     return $tableName;
 }
コード例 #4
0
ファイル: EventStore.php プロジェクト: ad3n/event-store
 /**
  * @param StreamName $streamName
  * @param null|int $minVersion
  * @throws Exception\StreamNotFoundException
  * @return Stream
  */
 public function load(StreamName $streamName, $minVersion = null)
 {
     $argv = ['streamName' => $streamName, 'minVersion' => $minVersion];
     $event = $this->actionEventEmitter->getNewActionEvent(__FUNCTION__ . '.pre', $this, $argv);
     $this->getActionEventEmitter()->dispatch($event);
     if ($event->propagationIsStopped()) {
         $stream = $event->getParam('stream', false);
         if ($stream instanceof Stream && $stream->streamName()->toString() == $streamName->toString()) {
             return $stream;
         }
         throw new StreamNotFoundException(sprintf('A stream with name %s could not be found', $streamName->toString()));
     }
     $streamName = $event->getParam('streamName');
     $minVersion = $event->getParam('minVersion');
     $stream = $this->adapter->load($streamName, $minVersion);
     if (!$stream) {
         throw new StreamNotFoundException(sprintf('A stream with name %s could not be found', $streamName->toString()));
     }
     $event->setName(__FUNCTION__ . '.post');
     $event->setParam('stream', $stream);
     $this->getActionEventEmitter()->dispatch($event);
     if ($event->propagationIsStopped()) {
         throw new StreamNotFoundException(sprintf('A stream with name %s could not be found', $streamName->toString()));
     }
     return $event->getParam('stream');
 }
コード例 #5
0
 /**
  * @param StreamName $streamName
  * @param DateTimeInterface|null $since
  * @param array $metadata
  * @return ArrayIterator
  */
 public function replay(StreamName $streamName, DateTimeInterface $since = null, array $metadata = [])
 {
     if (!isset($this->streams[$streamName->toString()])) {
         return new ArrayIterator();
     }
     $streamEvents = [];
     foreach ($this->streams[$streamName->toString()] as $index => $streamEvent) {
         if (null === $since && $this->matchMetadataWith($streamEvent, $metadata)) {
             $streamEvents[] = $streamEvent;
         } elseif ($streamEvent->createdAt()->format('U.u') >= $since->format('U.u') && $this->matchMetadataWith($streamEvent, $metadata)) {
             $streamEvents[] = $streamEvent;
         }
     }
     return new ArrayIterator($streamEvents);
 }
コード例 #6
0
 /**
  * @param StreamName $streamName
  * @return string
  */
 private function getCollectionName(StreamName $streamName)
 {
     if (isset($this->streamCollectionMap[$streamName->toString()])) {
         $collectionName = $this->streamCollectionMap[$streamName->toString()];
     } else {
         $collectionName = strtolower($this->getShortStreamName($streamName));
         if (strpos($collectionName, "_stream") === false) {
             $collectionName .= "_stream";
         }
     }
     return $collectionName;
 }