79 lines
1.8 KiB
PHP
79 lines
1.8 KiB
PHP
<?php
|
|
|
|
class mfResponse {
|
|
|
|
public static function isResponse($test) {
|
|
if(is_array($test) && array_key_exists('code', $test) && array_key_exists('status', $test)) {
|
|
if($test['code'] >= 100 && $test['code'] < 600) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static function Ok($data = []) {
|
|
$response = [];
|
|
$response['code'] = 200;
|
|
$response['status'] = "OK";
|
|
$response["data"] = $data;
|
|
return $response;
|
|
}
|
|
|
|
public static function Created($data = []) {
|
|
$response = [];
|
|
$response['code'] = 201;
|
|
$response['status'] = "Created";
|
|
$response["data"] = $data;
|
|
return $response;
|
|
}
|
|
|
|
public static function NotFound($data = []) {
|
|
$response = [];
|
|
$response['code'] = 404;
|
|
$response['status'] = "Not Found";
|
|
$response["data"] = $data;
|
|
return $response;
|
|
}
|
|
|
|
public static function BadRequest($data = []) {
|
|
$response = [];
|
|
$response['code'] = 400;
|
|
$response['status'] = "Bad Request";
|
|
$response["data"] = $data;
|
|
return $response;
|
|
}
|
|
|
|
public static function InternalServerError($data = []) {
|
|
$response = [];
|
|
$response['code'] = 500;
|
|
$response['status'] = "Internal Server Error";
|
|
$response["data"] = $data;
|
|
return $response;
|
|
}
|
|
|
|
public static function Unauthorized($data = []) {
|
|
$response = [];
|
|
$response['code'] = 401;
|
|
$response['status'] = "Unauthorized";
|
|
$response["data"] = $data;
|
|
return $response;
|
|
}
|
|
|
|
public static function Forbidden($data = []) {
|
|
$response = [];
|
|
$response['code'] = 403;
|
|
$response['status'] = "Forbidden";
|
|
$response["data"] = $data;
|
|
return $response;
|
|
}
|
|
|
|
public static function ImATeaPot($data = []) {
|
|
$response = [];
|
|
$response['code'] = 418;
|
|
$response['status'] = "I'm a teapot";
|
|
$response["data"] = $data;
|
|
return $response;
|
|
}
|
|
|
|
|
|
} |