diff --git a/src/web/php/lib/json_builder.php b/src/web/php/lib/json_builder.php new file mode 100644 index 0000000..d6d62d3 --- /dev/null +++ b/src/web/php/lib/json_builder.php @@ -0,0 +1,51 @@ +arguemnt_array = array(); + } + + function __destruct() + { + } + + + public function setData($name, $data) + { + $this->arguemnt_array[$name] = $data; + } + + public function setErrorMessage($message) + { + $this->arguemnt_array["error"] = $message; + } + + public function setErrorCode($code) + { + $this->setData("errorCode", $code); + } + + public function send() + { + echo json_encode($this->arguemnt_array, JSON_UNESCAPED_UNICODE); + } + + public function sendResultSuccess() + { + $this->arguemnt_array["result"] = "success"; + $this->send(); + } + + public function sendResultFail() + { + $this->arguemnt_array["result"] = "fail"; + $this->send(); + } + +} + +?> \ No newline at end of file diff --git a/src/web/php/lib/send_reply_json.php b/src/web/php/lib/send_reply_json.php deleted file mode 100644 index f64b7c4..0000000 --- a/src/web/php/lib/send_reply_json.php +++ /dev/null @@ -1,39 +0,0 @@ -close(); -} - -function set_error_code($data) { - set_data("error_code", $data); -} - -function send_result_fail() { - global $jsonReply; - global $db_conn; - - $jsonReply["result"] = "fail"; - echo json_encode($jsonReply, JSON_UNESCAPED_UNICODE); - $db_conn->close(); -} - -?> \ No newline at end of file diff --git a/src/web/php/writing/player_list.php b/src/web/php/writing/player_list.php index dd527a2..a7d23d7 100644 --- a/src/web/php/writing/player_list.php +++ b/src/web/php/writing/player_list.php @@ -2,16 +2,17 @@ header('Content-Type: application/json'); include "./../lib/connect_db.php"; +include "./../lib/json_builder.php"; -$jsonReply = array(); +$dbConnector = new DBConnector(); +$isConnected = $dbConnector->connectDB(); -$db_conn = new DBConnector(); -$isConnected = $db_conn->connectDB(); +$jsonBuilder = new JsonBuilder(); +$jsonBuilder->setData("isConnected", $isConnected); +$jsonBuilder->setData("dbVariables", $dbConnector->getDBVariables()); +$jsonBuilder->sendResultSuccess(); -$jsonReply["isConnected"] = $isConnected; -$jsonReply["dbVariables"] = $db_conn->getDBVariables(); -echo json_encode($jsonReply, JSON_UNESCAPED_UNICODE); /*