public function execute(Command $command, Responder $responder) { $post = Post::create($command->getTitle(), $command->getContent()); try { $this->eventBus->dispatch($post->getEvents()); $this->eventStorage->add($post); } catch (\Exception $e) { $responder->postPublishingFailed($e); } $responder->postPublishedSuccessfully($post); }
public function execute(Command $command, Responder $responder) { $comment = Comment::create($command->getPostId(), $command->getAuthor(), $command->getContent()); try { $this->eventBus->dispatch($comment->getEvents()); $this->eventStorage->add($comment); } catch (\Exception $e) { $responder->commentAddingFailed($e); } $responder->commentAddedSuccessfully($comment); }
private function checkEventStorage() { if ($this->forced === true) { return; } $storedEvents = $this->eventStorage->getAll(); foreach ($storedEvents as $storedEvent) { if (get_class($storedEvent) != 'Domain\\EventModel\\Event\\ThemeWasCreated') { throw new EventStorageNotEmptyException(); } } }
public function execute(Command $command, Responder $responder) { $postAggregateHistory = new PostAggregateHistory($command->getPostId(), $this->eventStorage); $post = Post::reconstituteFrom($postAggregateHistory); $post->update($command->getTitle(), $command->getContent()); try { $this->eventBus->dispatch($post->getEvents()); $this->eventStorage->add($post); } catch (\Exception $e) { $responder->postUpdatingFailed($e); } $responder->postUpdatedSuccessfully($post); }
private function populate() { $events = $this->eventStorage->getAll(); foreach ($events as $event) { $this->stats->increaseTotalEvents(); $eventClass = explode('\\', get_class($event)); $method = 'on' . end($eventClass); if (method_exists($this->listener, $method)) { $this->listener->when($event); $this->stats->increaseProcessedEvents(); } } $this->projectionStorage->flush(); $this->stats->setPopulatedProjections(count($this->projectionStorage->find(static::getProjectionName()))); }
function it_should_run_populator(BulkProjectionStorage $projectionStorage, EventStorage $eventStorage, DomainEventListener $listener) { $projectionStorage->find('post-list')->willReturn($projections = [new PostListProjection(PostId::generate(), 'Post title', new \DateTime())]); foreach ($projections as $projection) { $projectionStorage->remove($projection)->shouldBeCalled(); } $projectionStorage->flush()->shouldBeCalled(); $eventStorage->getAll()->willReturn($events = [new PostWasPublished(PostId::generate(), 'title', 'content', new \DateTime())]); foreach ($events as $event) { $eventClass = explode('\\', get_class($event)); $method = 'on' . end($eventClass); if (method_exists($listener, $method)) { $listener->when($event)->shouldBeCalled(); } } $projectionStorage->flush()->shouldBeCalled(); $this->run(); }