Prooph\EventStore\Aggregate\AggregateType::assert PHP Method

assert() public method

public assert ( $aggregateRoot )
$aggregateRoot
    public function assert($aggregateRoot)
    {
        $otherAggregateType = self::fromAggregateRoot($aggregateRoot);
        if (!$this->equals($otherAggregateType)) {
            throw new Exception\AggregateTypeException(sprintf('Aggregate types must be equal. %s != %s', $this->toString(), $otherAggregateType->toString()));
        }
    }

Usage Example

 /**
  * @param object $eventSourcedAggregateRoot
  * @throws Exception\AggregateTypeException
  */
 public function addAggregateRoot($eventSourcedAggregateRoot)
 {
     $this->aggregateType->assert($eventSourcedAggregateRoot);
     $domainEvents = $this->aggregateTranslator->extractPendingStreamEvents($eventSourcedAggregateRoot);
     $aggregateId = $this->aggregateTranslator->extractAggregateId($eventSourcedAggregateRoot);
     $streamName = $this->determineStreamName($aggregateId);
     $enrichedEvents = [];
     foreach ($domainEvents as $event) {
         $enrichedEvents[] = $this->enrichEventMetadata($event, $aggregateId);
     }
     if ($this->oneStreamPerAggregate) {
         $stream = new Stream($streamName, new ArrayIterator($enrichedEvents));
         $this->eventStore->create($stream);
     } else {
         $this->eventStore->appendTo($streamName, new ArrayIterator($enrichedEvents));
     }
 }
All Usage Examples Of Prooph\EventStore\Aggregate\AggregateType::assert