original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Initializes the stored aggregate with its events persisted in event store.
  
  @param AggregateId $aggregateId
  @return EventSourcedAggregateRoot
  @throws InvalidArgumentException If the $aggregateId is invalid
docstring_tokens: Initializes the stored aggregate with its events persisted in event store .