示例#1
0
 /**
  * test grabbing a player that does not exist
  **/
 public function testGetInvalidPlayerByPlayerId()
 {
     // grab a player that exceeds the maximum allowable team id
     $player = Player::getPlayerByPlayerId($this->getPDO(), SprotsTest::INVALID_KEY);
     $this->assertNull($player);
 }
示例#2
0
    //determine which HTTP method was used
    $method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
    //sanitize inputs
    $id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
    //make sure the id is valid for methods that require it
    if (($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) {
        throw new InvalidArgumentException("id can not be empty or negative", 405);
    }
    //sanitize and trim other fields
    $playerId = filter_input(INPUT_GET, "playerId", FILTER_VALIDATE_INT);
    $playerTeamId = filter_input(INPUT_GET, "playerTeamId", FILTER_VALIDATE_INT);
    $playerSportId = filter_input(INPUT_GET, "playerSportId", FILTER_VALIDATE_INT);
    $playerName = filter_input(INPUT_GET, "playerName", FILTER_SANITIZE_STRING);
    //get the player based on the given field
    if (empty($id) === false) {
        $player = Player::getPlayerByPlayerId($pdo, $id);
        $reply->data = $player;
    } elseif (empty($teamId) === false) {
        $player = Player::getPlayerByPlayerTeamId($pdo, $playerTeamId);
        $reply->date = $player;
    } elseif (empty($sportId) === false) {
        $player = Player::getPlayerByPlayerSportId($pdo, $playerSportId);
        $reply->date = $player;
    } elseif (empty($playerName) === false) {
        $player = Player::getPlayerByPlayerName($pdo, $playerName);
        $reply->date = $player;
    } else {
        $reply->data = Player::getAllPlayers($pdo)->toArray();
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();