/** * @param object $message * @param callable $next */ public function handle($message, callable $next) { $this->logger->debug('NotifiesDomainEvents calls next before collect events'); $next($message); $events = $this->collectsEventsFromEntities->recordedMessages(); $this->collectsEventsFromEntities->eraseMessages(); $this->logger->debug('NotifiesDomainEvents notifies ' . count($events) . ' events'); foreach ($events as $event) { $this->eventBus->handle($event); } }
/** * @param object $message * @param callable $next * * @throws Exception */ public function handle($message, callable $next) { $next($message); $events = $this->collectsEventsFromEntities->recordedMessages(); $count = count($events); $this->logger->debug('MonitorsDomainEvents saw ' . $count . ' events'); if ($count) { foreach ($events as $event) { $this->logger->debug('MonitorsDomainEvents saw ' . get_class($event)); } if ($count == 1) { $message = sprintf('%s Domain Event has been collected but will not be notified. You should not raise domain event during the handling of a Event message but only for a Command.', get_class(array_pop($events))); } else { $message = sprintf('%s Domain Event(s) have been collected but will not be notified. You should not raise domain event during the handling of a Event message but only for a Command.', $count); } throw new Exception($message); } }