src/Model/Aggregate/AggregateRoot.php
public function reconstituteFrom(AggregateRootEventList $history)
    {
        if (!$this->history->isEmpty()) {
            throw new ReconstitutionError('Trying to reconstitute history on an already initialized aggregate-root.');
        }

        $first = true;
        foreach ($history as $past_event) {
            if ($first) {
                $first = false;
                if (!$past_event instanceof AggregateRootCreatedEvent) {
                    throw new ReconstitutionError(
                        sprintf(
                            'The first event given within a history to reconstitute from must be by the type of "%s".' .
                            ' Instead "%s" was given for AR %s.',
                            AggregateRootCreatedEvent::CLASS,
                            get_class($past_event),
                            $past_event->getAggregateRootIdentifier()
                        )
                    );
                }
            }

            $this->history->push($this->applyEvent($past_event, false));
        }

        return $this->isValid();
    }
public function reconstituteFrom(AggregateRootEventList $history)
    {
        if (!$this->history->isEmpty()) {
            throw new ReconstitutionError('Trying to reconstitute history on an already initialized aggregate-root.');
        }

        $first = true;
        foreach ($history as $past_event) {
            if ($first) {
                $first = false;
                if (!$past_event instanceof AggregateRootCreatedEvent) {
                    throw new ReconstitutionError(
                        sprintf(
                            'The first event given within a history to reconstitute from must be by the type of "%s".' .
                            ' Instead "%s" was given for AR %s.',
                            AggregateRootCreatedEvent::CLASS,
                            get_class($past_event),
                            $past_event->getAggregateRootIdentifier()
                        )
                    );
                }
            }

            $this->history->push($this->applyEvent($past_event, false));
        }

        return $this->isValid();
    }
public function reconstituteFrom ( AggregateRootEventList $ history ) { if ( ! $ this -> history -> isEmpty ( ) ) { throw new ReconstitutionError ( 'Trying to reconstitute history on an already initialized aggregate-root.' ) ; } $ first = true ; foreach ( $ history as $ past_event ) { if ( $ first ) { $ first = false ; if ( ! $ past_event instanceof AggregateRootCreatedEvent ) { throw new ReconstitutionError ( sprintf ( 'The first event given within a history to reconstitute from must be by the type of "%s".' . ' Instead "%s" was given for AR %s.' , AggregateRootCreatedEvent :: CLASS , get_class ( $ past_event ) , $ past_event -> getAggregateRootIdentifier ( ) ) ) ; } } $ this -> history -> push ( $ this -> applyEvent ( $ past_event , false ) ) ; } return $ this -> isValid ( ) ; }
Rebuild an aggregate-root's latest state based on the given audit log.

@param AggregateRootEventList $history
Rebuild an aggregate - root s latest state based on the given audit log .