-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponse.php
More file actions
executable file
·68 lines (58 loc) · 1.65 KB
/
Copy pathResponse.php
File metadata and controls
executable file
·68 lines (58 loc) · 1.65 KB
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
<?php
namespace Pet\Router;
use Exception;
use Pet\Errors\AppException;
use Pet\Errors\Errors;
use Pet\Request\Request;
use Pet\Tools\Tools;
class Response
{
public function __construct(int $status = 200){
Header::status($status);
}
/**
* redirect
* @param string $path
* @return void
*/
public static function redirect(string $path): void
{
if ($path == request()->path) {
Error::setHttp(HTTP::FATAL, "redirect to itself is prohibited");
throw new AppException("redirect to itself is prohibited", E_ERROR);
} else {
if (!Header::sent()) {
ob_clean();
Header::location($path);
}
}
}
public static function code(int $code): void {
Header::status($code);
}
public static function echo(mixed $data): void
{
!Header::sent()? Header::type(Header::HTML) : '';
echo $data;
}
public static function json(array|object $data, $code = HTTP::SUCCESS):void
{
Header::status($code);
!Header::sent() ? Header::json() : '';
die(json_encode($data, JSON_UNESCAPED_UNICODE));
}
public static function html(string $data, $code = HTTP::SUCCESS) {
Header::status($code);
!Header::sent() ? Header::html() : '';
die($data);
}
public static function text(string $data, $code = HTTP::SUCCESS) {
Header::status($code);
!Header::sent() ? Header::html() : '';
die($data);
}
public static function svg(string $data, $code = HTTP::SUCCESS) {
Header::type(Header::SVG);
die($data);
}
}