Import alt-mysql plugin

This commit is contained in:
Marek Miklewicz
2026-07-04 15:48:19 +02:00
commit d71fcf9ace
101 changed files with 18635 additions and 0 deletions
+128
View File
@@ -0,0 +1,128 @@
<?php
declare(strict_types=1);
final class Http
{
public static function bootstrapGlobals(): void
{
if (PHP_SAPI !== 'cli') {
return;
}
$query = getenv('QUERY_STRING') ?: '';
$method = strtoupper((string)(getenv('REQUEST_METHOD') ?: 'GET'));
$_GET = [];
if ($query !== '') {
parse_str($query, $_GET);
}
$queryAction = strtolower(trim((string)($_GET['action'] ?? '')));
$_POST = [];
if ($method === 'POST') {
$rawPost = (string)(getenv('POST') ?: '');
if ($rawPost === '') {
$rawPost = (string)(getenv('HTTP_POST') ?: '');
}
$contentType = strtolower((string)(getenv('CONTENT_TYPE') ?: ''));
$isUrlEncoded = ($contentType === '' || str_contains($contentType, 'application/x-www-form-urlencoded'));
if ($rawPost === '' && $isUrlEncoded) {
if ($queryAction !== 'upload_blob') {
$stdin = @file_get_contents('php://stdin');
if (is_string($stdin) && $stdin !== '') {
$rawPost = $stdin;
}
}
}
if ($rawPost !== '') {
parse_str($rawPost, $_POST);
}
}
$_REQUEST = array_merge($_GET, $_POST);
$_SERVER['REQUEST_METHOD'] = $method;
$_SERVER['QUERY_STRING'] = $query;
$knownServerVars = [
'USER',
'USERNAME',
'HOME',
'LANGUAGE',
'SESSION_ID',
'REQUEST_URI',
'HTTP_HOST',
'HTTPS',
'HTTP_USER_AGENT',
'HTTP_X_FORWARDED_PROTO',
'HTTP_FRONT_END_HTTPS',
'REQUEST_SCHEME',
'SERVER_NAME',
'SERVER_PORT',
'REMOTE_ADDR',
];
foreach ($knownServerVars as $key) {
if (!isset($_SERVER[$key])) {
$value = getenv($key);
if ($value !== false) {
$_SERVER[$key] = $value;
}
}
}
}
public static function method(): string
{
return strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? 'GET'));
}
public static function isPost(): bool
{
return self::method() === 'POST';
}
public static function getString(array $source, string $key, string $default = ''): string
{
if (!isset($source[$key])) {
return $default;
}
$value = $source[$key];
if (is_array($value)) {
return $default;
}
return trim((string)$value);
}
public static function getArray(array $source, string $key): array
{
if (!isset($source[$key])) {
return [];
}
$value = $source[$key];
if (!is_array($value)) {
return [];
}
return $value;
}
public static function server(string $key, string $default = ''): string
{
$value = $_SERVER[$key] ?? null;
if ($value === null) {
return $default;
}
return trim((string)$value);
}
public static function redirect(string $url): void
{
header('Location: ' . $url, true, 302);
exit;
}
}