Example #1
0
 /**
  * @param Vote $vote
  *
  * @return string
  * @validate $vote \Visol\Votable\Domain\Validator\VoteDoesNotExistValidator
  */
 public function addAction(Vote $vote)
 {
     // Send signal
     $signalResult = $this->getSignalSlotDispatcher()->dispatch(self::class, 'beforeVoteChange', [$vote, 'add']);
     /** @var Vote $vote */
     $vote = $signalResult[0];
     $this->voteRepository->add($vote);
     $this->view->assign('vote', $vote);
     // Send signal
     $this->getSignalSlotDispatcher()->dispatch(self::class, 'afterVoteChange', [$vote, 'add']);
     $this->response->setHeader('Content-Type', 'application/json');
     return json_encode(['action' => 'add', 'success' => $this->voteRepository->exists($vote), 'identifier' => $vote->getUid()]);
 }