コード例 #1
0
ファイル: ApiController.php プロジェクト: axelchalon/navale
 /**
  * @ApiDoc(
  *      description="Rejoint une partie.",
  *      section="1 - Parties",
  *      statusCodes={
  *          200: "Partie rejointe. Renvoie le secret du joueur.",
  *          403: "Mauvais mot de passe pour rejoindre la partie, ou bien la partie est déjà remplie."
  *      }
  * )
  * @RequestParam(name="password", nullable=true, description="Mot de passe de la partie")
  * @Post("/api/v1/games/{game_id}/players", name="join_game_api")
  * @Post("/games/{game_id}/players", name="join_game")
  * @ParamConverter("game", class="AppBundle:Game", options={"id" = "game_id"})
  */
 public function joinGameAction(Game $game, ParamFetcher $paramFetcher)
 {
     if ($game->getPassword() !== $paramFetcher->get('password')) {
         throw new HttpException(400, 'Bad password.');
     }
     if ($game->isFull()) {
         throw new HttpException(400, 'Game is already full.');
     }
     $game->generateP2Secret();
     $em = $this->getDoctrine()->getEntityManager();
     $em->persist($game);
     $em->flush();
     return $this->view(array('secret' => $game->getP2Secret()))->setTemplate('AppBundle:Api:player_join.html.twig')->setTemplateData(array('game' => $game, 'secret' => $game->getP2Secret()));
 }