예제 #1
0
                if ($result != null) {
                    header("Content-type: application/json");
                    print $result->getJSON();
                    exit;
                } else {
                    header("HTTP/1.0 400 Bad Request");
                    print "Username is already taken";
                    exit;
                }
            }
            if ($path_components[1] == "game") {
                $name = $path_components[2];
                $aiName = $path_components[3];
                $playerScore = $path_components[4];
                $aiScore = $path_components[5];
                $playerId = Player::findByUserName($name)->getID();
                $aiId = Ai::findByName($aiName)->getID();
                $result = Game::create($playerId, $aiId, $playerScore, $aiScore);
                if ($result != null) {
                    header("Content-type: application/json");
                    print $result->getJSON();
                    exit;
                } else {
                    header("HTTP/1.0 404 Bad Request");
                    print "Something went wrong";
                    exit;
                }
            }
        }
    }
}