public function load(AggregateId $aggregateId) : AggregateRoot
    {
        $aggregateRootClass = ObjectClass::forName($aggregateId->aggregateClass());
        $aggregate = null;
        $stateHash = null;
        if ($this->eventStore instanceof SnapshotEventStore) {
            $aggregate = $this->eventStore->loadSnapshot($aggregateId);
            $stateHash = $aggregate === null
                ? null
                : $aggregate->stateHash();
        }
        $events = $this->eventStore->getEventsFor($aggregateId, $stateHash);
        if ($aggregate === null) {
            Preconditions::checkArgument($events->valid(), 'Aggregate with ID [%s] does not exist', $aggregateId);
            $aggregate = $aggregateRootClass->newInstanceWithoutConstructor();
        }
        $aggregateRootClass->cast($aggregate);
        $aggregate->loadFromHistory($events);
        return $aggregate;
    }
public function load(AggregateId $aggregateId) : AggregateRoot
    {
        $aggregateRootClass = ObjectClass::forName($aggregateId->aggregateClass());
        $aggregate = null;
        $stateHash = null;
        if ($this->eventStore instanceof SnapshotEventStore) {
            $aggregate = $this->eventStore->loadSnapshot($aggregateId);
            $stateHash = $aggregate === null
                ? null
                : $aggregate->stateHash();
        }
        $events = $this->eventStore->getEventsFor($aggregateId, $stateHash);
        if ($aggregate === null) {
            Preconditions::checkArgument($events->valid(), 'Aggregate with ID [%s] does not exist', $aggregateId);
            $aggregate = $aggregateRootClass->newInstanceWithoutConstructor();
        }
        $aggregateRootClass->cast($aggregate);
        $aggregate->loadFromHistory($events);
        return $aggregate;
    }
public function load ( AggregateId $ aggregateId ) : AggregateRoot { $ aggregateRootClass = ObjectClass :: forName ( $ aggregateId -> aggregateClass ( ) ) ; $ aggregate = null ; $ stateHash = null ; if ( $ this -> eventStore instanceof SnapshotEventStore ) { $ aggregate = $ this -> eventStore -> loadSnapshot ( $ aggregateId ) ; $ stateHash = $ aggregate === null ? null : $ aggregate -> stateHash ( ) ; } $ events = $ this -> eventStore -> getEventsFor ( $ aggregateId , $ stateHash ) ; if ( $ aggregate === null ) { Preconditions :: checkArgument ( $ events -> valid ( ) , 'Aggregate with ID [%s] does not exist' , $ aggregateId ) ; $ aggregate = $ aggregateRootClass -> newInstanceWithoutConstructor ( ) ; } $ aggregateRootClass -> cast ( $ aggregate ) ; $ aggregate -> loadFromHistory ( $ events ) ; return $ aggregate ; }
Initializes the stored aggregate with its events persisted in event store.

@param AggregateId $aggregateId
@return EventSourcedAggregateRoot
@throws InvalidArgumentException If the $aggregateId is invalid
Initializes the stored aggregate with its events persisted in event store .