Add: json_builder.php
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
class JsonBuilder
|
||||
{
|
||||
private $arguemnt_array;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
$jsonReply = array();
|
||||
|
||||
function set_error_message($message) {
|
||||
global $jsonReply;
|
||||
|
||||
$jsonReply["error"] = $message;
|
||||
}
|
||||
|
||||
function set_data($name, $data) {
|
||||
global $jsonReply;
|
||||
|
||||
$jsonReply[$name] = $data;
|
||||
}
|
||||
|
||||
function send_result_success() {
|
||||
global $jsonReply;
|
||||
global $db_conn;
|
||||
|
||||
$jsonReply["result"] = "success";
|
||||
echo json_encode($jsonReply, JSON_UNESCAPED_UNICODE);
|
||||
$db_conn->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();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user