/** * @param DomainEventInterface $event */ protected function publishEvent(DomainEventInterface $event) { DomainEventPublisher::publish($event); }
/** * Save the aggregate history. * * @param EventSourcedAggregateRootInterface $aggregateRoot */ protected function saveHistory(EventSourcedAggregateRootInterface $aggregateRoot) { $recordedEvents = $aggregateRoot->recordedEvents(); if (count($recordedEvents) > 0) { DomainEventPublisher::publish(new PrePersistEvent($aggregateRoot)); // clear events $aggregateRoot->clearEvents(); // create the eventStream and persist it $applicationVersion = VersionManager::currentApplicationVersion(); $eventStream = new EventStream($this->streamName(), $aggregateRoot->id(), $recordedEvents); $this->eventStore->persist($eventStream, $aggregateRoot->version(), $applicationVersion); DomainEventPublisher::publish(new PostPersistEvent($aggregateRoot)); } }
/** * Test set method. */ public function testSet() { $this->given($incrementEvent = new IncrementCounterEvent(5))->and($decrementEvent = new DecrementCounterEvent(3))->and($counterSubscriber = new CounterEventSubscriber())->and(DomainEventPublisher::set(EventBus::create()))->and(DomainEventPublisher::subscribe($counterSubscriber))->when(DomainEventPublisher::publish($incrementEvent))->then()->integer($counterSubscriber->counter())->isEqualTo(5)->when(DomainEventPublisher::publish($incrementEvent))->then()->integer($counterSubscriber->counter())->isEqualTo(10)->when(DomainEventPublisher::publish($decrementEvent))->then()->integer($counterSubscriber->counter())->isEqualTo(7); }