Total Complexity | 7 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
6 | class RedirectResponse extends HttpResponse |
||
7 | { |
||
8 | |||
9 | public $headers; |
||
10 | public $body; |
||
11 | |||
12 | public function __construct($url, $htmx = false, $parse = true, $code = 302, $redirect_after = null ) |
||
13 | { |
||
14 | if ($this->isLocalUrl($url) && $parse) { |
||
15 | $parsedUrl = Application::getDir()."/".$url; |
||
16 | } else { |
||
17 | $parsedUrl = $url; |
||
18 | } |
||
19 | if ($htmx) { |
||
20 | $headers = ["HX-Redirect" => $parsedUrl]; |
||
21 | } else { |
||
22 | $headers = [ "Location" => $parsedUrl ]; |
||
23 | } |
||
24 | if(isset($redirect_after)){ |
||
25 | $_SESSION["redirect_url"] = $redirect_after; |
||
26 | |||
27 | } |
||
28 | parent::__construct(body: '', statusCode: $code, headers: $headers); |
||
29 | } |
||
30 | |||
31 | public function isLocalUrl($url) |
||
35 | } |
||
36 | |||
39 |