/** * @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 object $command * @return mixed */ public function getAggregateIdentifier($command) { return $this->first->getAggregateIdentifier($command) ?: $this->second->getAggregateIdentifier($command); }