2017-12-24 20:00:45 +01:00
|
|
|
<?php
|
|
|
|
class Response {
|
2018-01-05 06:07:00 +01:00
|
|
|
private static function defaultHeaders () {
|
2018-01-08 00:01:40 +01:00
|
|
|
header('Access-Control-Allow-Origin: *');
|
2018-01-05 06:07:00 +01:00
|
|
|
header('Expires: Sun, 01 Nov 2015 22:46:51 GMT');
|
|
|
|
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
|
|
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
|
|
|
header("Pragma: no-cache");
|
|
|
|
}
|
|
|
|
|
2017-12-24 22:19:42 +01:00
|
|
|
public static function json ($data, $http_code = 200) {
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
2018-01-05 06:07:00 +01:00
|
|
|
Response::defaultHeaders();
|
2017-12-24 20:00:45 +01:00
|
|
|
http_response_code($http_code);
|
|
|
|
echo json_encode($data);
|
2017-12-24 22:19:42 +01:00
|
|
|
}
|
2018-01-05 06:07:00 +01:00
|
|
|
|
2017-12-24 22:19:42 +01:00
|
|
|
public static function html ($html, $http_code = 200) {
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
2018-01-05 06:07:00 +01:00
|
|
|
Response::defaultHeaders();
|
2017-12-24 22:19:42 +01:00
|
|
|
http_response_code($http_code);
|
|
|
|
echo $html;
|
2017-12-24 20:00:45 +01:00
|
|
|
}
|
|
|
|
}
|