Exemplo n.º 1
0
 /**
  * Rebuild an aggregate-root's latest state based on the given audit log.
  *
  * @param AggregateRootEventList $history
  */
 public function reconstituteFrom(AggregateRootEventList $history)
 {
     if (!$this->history->isEmpty()) {
         throw new RuntimeError('Trying to reconstitute a history on a already initialized aggregate-root.');
     }
     $first = true;
     foreach ($history as $past_event) {
         if ($first) {
             $first = false;
             if (!$past_event instanceof AggregateRootCreatedEvent) {
                 throw new RuntimeError(sprintf('The first event given within a history to reconstitue 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();
 }
 protected function loadHistory()
 {
     $identifier = $this->getData($this->getArgument());
     if ($identifier instanceof EntityInterface) {
         $identifier = $identifier->getIdentifier();
     }
     $query_result = $this->getDomainEventQueryService()->findEventsByIdentifier($identifier);
     $history = new AggregateRootEventList($query_result->getResults());
     if ($history->isEmpty()) {
         return null;
     }
     return $history;
 }