-
Notifications
You must be signed in to change notification settings - Fork 0
/
Response.php
42 lines (40 loc) · 1.12 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
<?php
namespace sigawa\mvccore;
class Response
{
public function statusCode(int $code)
{
http_response_code($code);
}
public function setHeader(string $name, string $value)
{
header("$name: $value");
}
public function redirect(string $url, int $statusCode = 302)
{
http_response_code($statusCode);
header("Location: $url");
exit();
}
public function json($data, int $statusCode = 200)
{
$this->statusCode($statusCode);
$this->setHeader('Content-Type', 'application/json');
echo json_encode($data);
exit();
}
public function send(string $content, int $statusCode = 200)
{
$this->statusCode($statusCode);
echo $content;
exit();
}
public function setCookie(string $name, string $value, int $expire = 0, string $path = "", string $domain = "", bool $secure = false, bool $httponly = false)
{
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
}
public function deleteCookie(string $name)
{
setcookie($name, '', time() - 3600);
}
}