Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 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);
 }
 /**
  * @param EventBus $eventBus
  * @param ProjectionStorage $projectionStorage
  */
 public function __construct(EventBus $eventBus, ProjectionStorage $projectionStorage)
 {
     $eventBus->registerListener($this);
     $this->projectionStorage = $projectionStorage;
 }