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) { $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); }