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
|
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);
|
header('Location: ' . $url, true, 302);
|
||||||
exit;
|
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>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ name=global-autoresponder
|
|||||||
id=global-autoresponder
|
id=global-autoresponder
|
||||||
type=user
|
type=user
|
||||||
author=HITME.PL
|
author=HITME.PL
|
||||||
version=1.1.3
|
version=1.1.4
|
||||||
active=no
|
active=no
|
||||||
installed=no
|
installed=no
|
||||||
user_run_as=root
|
user_run_as=root
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require_once PLUGIN_ROOT . '/exec/lib/Http.php';
|
||||||
|
|
||||||
|
test('http redirect fallback renders visible html document for cli plugin runtime', function (): void {
|
||||||
|
$html = Http::redirectDocument('/CMD_PLUGINS/global-autoresponder/index.html?status=created');
|
||||||
|
|
||||||
|
assert_contains('<meta http-equiv="refresh"', $html);
|
||||||
|
assert_contains('window.location.replace', $html);
|
||||||
|
assert_contains('/CMD_PLUGINS/global-autoresponder/index.html?status=created', $html);
|
||||||
|
assert_contains('Przekierowanie', $html);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user