-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.php
More file actions
32 lines (24 loc) · 726 Bytes
/
response.php
File metadata and controls
32 lines (24 loc) · 726 Bytes
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
<?php
class Response {
private $message;
private $responseCode;
private $success;
public $data;
function __construct($message = "OK", $responseCode = 200) {
$this->message = $message;
$this->responseCode = $responseCode;
$this->success = $responseCode < 400;
$this->data = new stdClass();
}
function display() {
http_response_code($this->responseCode);
$response = new stdClass();
$response->message = $this->message;
$response->success = $this->success;
$response->data = $this->data;
header("Content-Type: application/json");
echo json_encode($response, JSON_PRETTY_PRINT);
exit();
}
}
?>