Skip to content

Commit

Permalink
make $_SERVER more detailed
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Sep 11, 2022
1 parent af028a8 commit 8fd287a
Showing 1 changed file with 105 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,112 @@ public static function getGlobalType(string $var_id): Union
}

if ($var_id === '$_SERVER' || $var_id === '$_ENV') {
$type = new TArray(
[
Type::getNonEmptyString(),
new Union([new TFloat(), new TIntRange(1, null), new TString(), new TNonEmptyList(Type::getString())]),
]
);

return new Union([$type]);
$string_helper = Type::getNonEmptyString();
$string_helper->possibly_undefined = true;

$non_empty_string_helper = Type::getNonEmptyString();
$non_empty_string_helper->possibly_undefined = true;

$argv_helper = new Union([
new TNonEmptyList(Type::getString())
]);
$argv_helper->possibly_undefined = true;

$argc_helper = new Union([
new TIntRange(1, null)
]);
$argc_helper->possibly_undefined = true;

$request_time_helper = new Union([
new TIntRange(time(), null)
]);
$request_time_helper->possibly_undefined = true;

$request_time_float_helper = Type::getFloat();
$request_time_float_helper->possibly_undefined = true;

$detailed_type = new TKeyedArray([
// https://www.php.net/manual/en/reserved.variables.server.php
'PHP_SELF' => $non_empty_string_helper,
'argv' => $argv_helper,
'argc' => $argc_helper,
'GATEWAY_INTERFACE' => $non_empty_string_helper,
'SERVER_ADDR' => $non_empty_string_helper,
'SERVER_NAME' => $non_empty_string_helper,
'SERVER_SOFTWARE' => $non_empty_string_helper,
'SERVER_PROTOCOL' => $non_empty_string_helper,
'REQUEST_METHOD' => $non_empty_string_helper,
'REQUEST_TIME' => $request_time_helper,
'REQUEST_TIME_FLOAT' => $request_time_float_helper,
'QUERY_STRING' => $string_helper,
'DOCUMENT_ROOT' => $non_empty_string_helper,
'HTTP_ACCEPT' => $non_empty_string_helper,
'HTTP_ACCEPT_CHARSET' => $non_empty_string_helper,
'HTTP_ACCEPT_ENCODING' => $non_empty_string_helper,
'HTTP_ACCEPT_LANGUAGE' => $non_empty_string_helper,
'HTTP_CONNECTION' => $non_empty_string_helper,
'HTTP_HOST' => $non_empty_string_helper,
'HTTP_REFERER' => $non_empty_string_helper,
'HTTP_USER_AGENT' => $non_empty_string_helper,
'HTTPS' => $string_helper,
'REMOTE_ADDR' => $non_empty_string_helper,
'REMOTE_HOST' => $non_empty_string_helper,
'REMOTE_PORT' => $string_helper,
'REMOTE_USER' => $non_empty_string_helper,
'REDIRECT_REMOTE_USER' => $non_empty_string_helper,
'SCRIPT_FILENAME' => $non_empty_string_helper,
'SERVER_ADMIN' => $non_empty_string_helper,
'SERVER_PORT' => $non_empty_string_helper,
'SERVER_SIGNATURE' => $non_empty_string_helper,
'PATH_TRANSLATED' => $non_empty_string_helper,
'SCRIPT_NAME' => $non_empty_string_helper,
'REQUEST_URI' => $non_empty_string_helper,
'PHP_AUTH_DIGEST' => $non_empty_string_helper,
'PHP_AUTH_USER' => $non_empty_string_helper,
'PHP_AUTH_PW' => $non_empty_string_helper,
'AUTH_TYPE' => $non_empty_string_helper,
'PATH_INFO' => $non_empty_string_helper,
'ORIG_PATH_INFO' => $non_empty_string_helper,
// misc from RFC not included above already http://www.faqs.org/rfcs/rfc3875.html
'CONTENT_LENGTH' => $string_helper,
'CONTENT_TYPE' => $string_helper,
// common, misc stuff
'FCGI_ROLE' => $non_empty_string_helper,
'HOME' => $non_empty_string_helper,
'HTTP_CACHE_CONTROL' => $non_empty_string_helper,
'HTTP_COOKIE' => $non_empty_string_helper,
'HTTP_PRIORITY' => $non_empty_string_helper,
'PATH' => $non_empty_string_helper,
'REDIRECT_STATUS' => $non_empty_string_helper,
'REQUEST_SCHEME' => $non_empty_string_helper,
'USER' => $non_empty_string_helper,
// common, misc headers
'HTTP_UPGRADE_INSECURE_REQUESTS' => $non_empty_string_helper,
'HTTP_X_FORWARDED_PROTO' => $non_empty_string_helper,
'HTTP_CLIENT_IP' => $non_empty_string_helper,
'HTTP_X_REAL_IP' => $non_empty_string_helper,
'HTTP_X_FORWARDED_FOR' => $non_empty_string_helper,
'HTTP_CF_CONNECTING_IP' => $non_empty_string_helper,
'HTTP_CF_IPCOUNTRY' => $non_empty_string_helper,
'HTTP_CF_VISITOR' => $non_empty_string_helper,
'HTTP_CDN_LOOP' => $non_empty_string_helper,
// common, misc browser headers
'HTTP_DNT' => $non_empty_string_helper,
'HTTP_SEC_FETCH_DEST' => $non_empty_string_helper,
'HTTP_SEC_FETCH_USER' => $non_empty_string_helper,
'HTTP_SEC_FETCH_MODE' => $non_empty_string_helper,
'HTTP_SEC_FETCH_SITE' => $non_empty_string_helper,
'HTTP_SEC_CH_UA_PLATFORM' => $non_empty_string_helper,
'HTTP_SEC_CH_UA_MOBILE' => $non_empty_string_helper,
'HTTP_SEC_CH_UA' => $non_empty_string_helper,
]);

// generic case for all other elements
$detailed_type->previous_key_type = Type::getNonEmptyString();
$detailed_type->previous_value_type = Type::getString();

return new Union([$detailed_type]);
}

if ($var_id === '$_FILES') {
Expand Down

0 comments on commit 8fd287a

Please sign in to comment.