-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
42 lines (35 loc) · 1 KB
/
api.php
File metadata and controls
42 lines (35 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
// Enable buffering
ob_start();
include_once("classes_php/Database.php");
include_once("classes_php/DataRequest.php");
header('Content-Type: application/json');
class Api {
public static function HandleDataRequest($request) {
$dataRequest = new DataRequest($request);
$db = new Database();
if(!$db) {
$dataResponse = new DataResponse();
$dataResponse->msg = $db->lastErrorMsg();
$dataResponse->setInvalid();
}
else {
$dataResponse = $db->Exec($dataRequest);
}
$db->close();
return $dataResponse;
}
public static function Main() {
if($_SERVER["REQUEST_METHOD"] == "POST") {
$input = file_get_contents('php://input');
$request = json_decode($input);
$response = self::HandleDataRequest($request);
echo json_encode($response);
}
else {
echo "GET METHOD NOT SUPPORTED";
}
}
}
Api::Main();
?>