blob: 4c9a794b47d446cad461ae892d5292eb647393ec (
plain)
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
|
<?php
namespace Digitigrade\HttpResponseStatus;
use Digitigrade\HttpResponseStatus;
class TemporaryRedirect extends \Exception implements HttpResponseStatus {
public string $target;
public function __construct(string $target) {
$this->target = $target;
$this->message = "Redirecting to $target";
}
public function httpCode(): int {
if (isset($_SERVER['HTTP_HX_REQUEST'])) {
return 200;
}
return 302;
}
public function httpReason(): string {
return "Found";
}
public function httpHeaders() {
if (isset($_SERVER['HTTP_HX_REQUEST'])) {
header("HX-Location: $this->target");
} else {
header("Location: $this->target");
}
}
}
|