-
Notifications
You must be signed in to change notification settings - Fork 0
/
Response.php
73 lines (65 loc) · 1.36 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace alvin\phpmvc;
/**
* http Response class
*/
class Response {
/**
* Sets a http status code.
*
* @param integer $code The status code to set
* @return void
*/
public function statusCode(int $code) {
http_response_code($code);
}
/**
* Set http redirect headers.
*
* @param string $url The url to redirect to
* @return void
*/
public function redirect($url) {
header("Location:$url");
}
/**
* Return a json response.
*
* @param array $obj obj to return
* @param integer $flags
* @param integer $depth
* @return object
*/
public function json(array $obj, int $flags = 0, int $depth = 512) {
header('Content-Type:application/json');
return json_encode($obj, $flags, $depth);
}
/**
* Set a cookie.
*
* @param string $key Cookie key
* @param string $value Cookie value
* @param array $options Cookie options
* @return boolean
*/
public function setCookie(string $key, string $value, array $options) {
return setCookie($key, $value, $options);
}
/**
* Remove a cookie.
* @param string $cookie key of cookie to remove
* @return boolean
*/
public function deleteCookie(string $cookie) {
return setCookie($cookie, NULL, 0 - 3600);
}
/**
* Send string.
* @param string $content string to send
* @return void
*/
public function send(string $content) {
echo $content;
exit();
}
}