1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lib\Http; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Psr7\Request as BaseRequest; |
6
|
|
|
|
7
|
|
|
class Request extends BaseRequest |
8
|
|
|
{ |
9
|
|
|
const METHOD_HEAD = 'HEAD'; |
10
|
|
|
const METHOD_GET = 'GET'; |
11
|
|
|
const METHOD_POST = 'POST'; |
12
|
|
|
|
13
|
|
|
protected $query; |
14
|
|
|
protected $request; |
15
|
|
|
protected $cookie; |
16
|
|
|
protected $server; |
17
|
|
|
protected $files; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* undocumented function |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
4 |
|
public function __construct($query = array(), $request = array(), $cookie = array(), $server = array(), $files = array()) |
25
|
|
|
{ |
26
|
4 |
|
$this->query = new ParamCollection($query); |
27
|
4 |
|
$this->request = new ParamCollection($request); |
28
|
4 |
|
$this->cookie = new ParamCollection($cookie); |
29
|
4 |
|
$this->server = new ServerCollection($server); |
30
|
4 |
|
$this->files = new ParamCollection($files); |
31
|
|
|
|
32
|
4 |
|
$method = $this->server->has('REQUEST_METHOD') ? $this->server->get('REQUEST_METHOD') : 'GET'; |
33
|
|
|
|
34
|
4 |
|
$requestUri = '/'; |
35
|
4 |
|
if ($this->server->has('REQUEST_URI')) { |
36
|
1 |
|
$requestUri = $this->server->get('REQUEST_URI'); |
37
|
3 |
|
} elseif ($this->server->has('ORIG_PATH_INFO')) { |
38
|
|
|
$requestUri = $this->server->get('ORIG_PATH_INFO'); |
39
|
|
|
$this->server->set('REQUEST_URI', $requestUri); |
40
|
|
|
} |
41
|
|
|
|
42
|
4 |
|
$version = $this->server->has('SERVER_PROTOCOL') ?? substr($this->server->get('SERVER_PROTOCOL'), -3) ?? '1.1'; |
43
|
|
|
|
44
|
4 |
|
parent::__construct($method, $requestUri, $this->server->getHeaders(), http_build_query($this->request->all()), $version); |
45
|
4 |
|
} |
46
|
|
|
|
47
|
1 |
|
public static function createFromGlobals() |
48
|
|
|
{ |
49
|
1 |
|
array_walk($_GET, 'htmlspecialchars'); |
50
|
1 |
|
array_walk($_POST, 'htmlspecialchars'); |
51
|
1 |
|
array_walk($_COOKIE, 'htmlspecialchars'); |
52
|
|
|
|
53
|
1 |
|
return new self( |
54
|
1 |
|
$_GET, |
55
|
1 |
|
$_POST, |
56
|
1 |
|
$_COOKIE, |
57
|
1 |
|
$_SERVER, |
58
|
1 |
|
$_FILES |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|