Prooph\EventStore\EventStore::load PHP Метод

load() публичный Метод

public load ( StreamName $streamName, null | integer $minVersion = null ) : Stream
$streamName Prooph\EventStore\Stream\StreamName
$minVersion null | integer
Результат Prooph\EventStore\Stream\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');
    }

Usage Example

Пример #1
0
 /**
  * Returns null if no stream events can be found for aggregate root otherwise the reconstituted aggregate root
  *
  * @param string $aggregateId
  * @return null|object
  */
 public function getAggregateRoot($aggregateId)
 {
     Assertion::string($aggregateId, 'AggregateId needs to be string');
     if ($this->snapshotStore) {
         $eventSourcedAggregateRoot = $this->loadFromSnapshotStore($aggregateId);
         if ($eventSourcedAggregateRoot) {
             //Cache aggregate root in the identity map
             $this->identityMap[$aggregateId] = $eventSourcedAggregateRoot;
             return $eventSourcedAggregateRoot;
         }
     }
     $streamName = $this->determineStreamName($aggregateId);
     $streamEvents = null;
     if ($this->oneStreamPerAggregate) {
         $streamEvents = $this->eventStore->load($streamName)->streamEvents();
     } else {
         $streamEvents = $this->eventStore->loadEventsByMetadataFrom($streamName, ['aggregate_type' => $this->aggregateType->toString(), 'aggregate_id' => $aggregateId]);
     }
     if (!$streamEvents->valid()) {
         return;
     }
     $eventSourcedAggregateRoot = $this->aggregateTranslator->reconstituteAggregateFromHistory($this->aggregateType, $streamEvents);
     //Cache aggregate root in the identity map but without pending events
     $this->identityMap[$aggregateId] = $eventSourcedAggregateRoot;
     return $eventSourcedAggregateRoot;
 }
All Usage Examples Of Prooph\EventStore\EventStore::load