Example #1
0
 /**
  * @param mixed $command
  * @return void
  * @throws \Exception
  */
 public function handle($command)
 {
     $aggregate = $this->aggregates->buildAggregateRoot($command);
     if (!is_object($aggregate)) {
         throw new \Exception('Aggregate root must be an object.');
     }
     $identifier = $this->aggregates->getAggregateIdentifier($command);
     $this->applyEvents($aggregate, $this->store->eventsOf($identifier));
     $events = $this->handleCommand($aggregate, $command);
     if (!$events) {
         return;
     } else {
         if (!is_array($events)) {
             $events = [$events];
         }
     }
     $this->appendEvents($events, $identifier);
     $this->tellListeners($events);
 }
 /**
  * @param mixed $command
  * @return object
  */
 public function buildAggregateRoot($command)
 {
     return $this->first->buildAggregateRoot($command) ?: $this->second->buildAggregateRoot($command);
 }