-
Notifications
You must be signed in to change notification settings - Fork 2
/
Response.php
40 lines (39 loc) · 1.04 KB
/
Response.php
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
<?php
class Response{
private static function setHeader($status,$body=""){
if($status!=""){
header("Access-Control-Allow-Origin: *");
header("HTTP/1.1 ".$status."");
header("Content-Type: application/json");
return json_encode(["status"=>$status,"body"=>$body]);
}
}
public static function json($content,$object=false){
// application/json
if($object==true){
return json_decode(self::setHeader(200,$content));
}else{
die(self::setHeader(200,$content));
}
}
public static function send(){ $status = 200; $content_type = 'application/json';
$args = func_get_args();
if(count($args) >0){
if(count($args) == 1){
$body = $args[0];
}elseif(count($args) == 2){
$status = $args[0];
$body = $args[1];
}else{
$status = $args[0];
$body = $args[1];
$content_type = $args[2];
}
header("Access-Control-Allow-Origin: *");
header("HTTP/1.1 ".$status."");
header("Content-Type: ".$content_type);
$send = json_encode(["status"=>$status,"body"=>$body]);
die($send);
}
}
}