31 lines
688 B
PHP
31 lines
688 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
final class Http
|
|
{
|
|
public static function method(): string
|
|
{
|
|
return strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? 'GET'));
|
|
}
|
|
|
|
public static function isPost(): bool
|
|
{
|
|
return self::method() === 'POST';
|
|
}
|
|
|
|
/**
|
|
* @param array<string,mixed> $source
|
|
*/
|
|
public static function getString(array $source, string $key, string $default = ''): string
|
|
{
|
|
$value = $source[$key] ?? $default;
|
|
return is_scalar($value) ? trim((string)$value) : $default;
|
|
}
|
|
|
|
public static function redirect(string $url): void
|
|
{
|
|
header('Location: ' . $url, true, 302);
|
|
exit;
|
|
}
|
|
}
|