fix: render redirects in cli runtime
This commit is contained in:
@@ -90,7 +90,25 @@ final class Http
|
||||
|
||||
public static function redirect(string $url): void
|
||||
{
|
||||
if (PHP_SAPI === 'cli') {
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
echo self::redirectDocument($url);
|
||||
exit;
|
||||
}
|
||||
header('Location: ' . $url, true, 302);
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function redirectDocument(string $url): string
|
||||
{
|
||||
$safeUrl = htmlspecialchars($url, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
$jsonUrl = json_encode($url, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
|
||||
return '<!doctype html><html lang="pl"><head><meta charset="utf-8">' .
|
||||
'<meta name="viewport" content="width=device-width, initial-scale=1">' .
|
||||
'<meta http-equiv="refresh" content="0;url=' . $safeUrl . '">' .
|
||||
'<title>Przekierowanie</title></head><body>' .
|
||||
'<p>Przekierowanie... <a href="' . $safeUrl . '">Kontynuuj</a></p>' .
|
||||
'<script>window.location.replace(' . $jsonUrl . ');</script>' .
|
||||
'</body></html>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user