From 7f95f77c0e029149f1dfea6ac529d0a3651e75fe Mon Sep 17 00:00:00 2001 From: Json <501807312@qq.com> Date: Wed, 28 Sep 2022 11:06:10 +0800 Subject: [PATCH] 1 --- src/Http/Request.php | 49 ++++++++++++++++++++++++++++++++++++++++++++ tests/test.php | 2 ++ 2 files changed, 51 insertions(+) diff --git a/src/Http/Request.php b/src/Http/Request.php index 5936f03..c9a4fdb 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -2,6 +2,8 @@ namespace Webguosai\Http; +use Webguosai\Util\Environment; + class Request { /** @@ -39,6 +41,53 @@ public static function get($key = null) return $data; } + /** + * 取得$_SERVER全局变量的值 + * + * @param null $key + * @param null $default + * @return null + */ + public static function server($key = null, $default = null) + { + if (!$key) { + return $_SERVER; + } + return isset($_SERVER[$key]) ? $_SERVER[$key] : $default; + } + + /** + * 获取请求头信息 + * + * @param string $name Content-Type + * @param null $default 默认值 + * @return array|false|null + */ + public static function getHeaders($name = '', $default = null) + { + $headers = []; + if (!empty($name)) { + $name = "HTTP_" . str_replace('-', '_', strtoupper($name)); + if (isset($_SERVER[$name])) { + return $_SERVER[$name]; + } else { + return $default; + } + } + if (!function_exists('getallheaders')) { + foreach ($_SERVER as $key => $value) + { + if (substr($key, 0, 5) == 'HTTP_') + { + $headers[ucwords(strtolower(str_replace('_', '-', substr($key, 5))), '-')] = $value; + } + } + } else { + $headers = getallheaders(); + } + return $headers; + } + /** * 是否为post请求 * diff --git a/tests/test.php b/tests/test.php index 5233187..7d114e9 100644 --- a/tests/test.php +++ b/tests/test.php @@ -147,6 +147,8 @@ /** Request **/ //dump(Request::getFullUrl()); //dump(Request::getReferer()); +//dump(Request::server('argv')); +//dump(Request::getHeaders()); /** Environment **/ //dump(Environment::get());