Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
webguosai committed Sep 28, 2022
1 parent c40341e commit 7f95f77
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Webguosai\Http;

use Webguosai\Util\Environment;

class Request
{
/**
Expand Down Expand Up @@ -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请求
*
Expand Down
2 changes: 2 additions & 0 deletions tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
/** Request **/
//dump(Request::getFullUrl());
//dump(Request::getReferer());
//dump(Request::server('argv'));
//dump(Request::getHeaders());

/** Environment **/
//dump(Environment::get());
Expand Down

0 comments on commit 7f95f77

Please sign in to comment.