-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathRequest.php
More file actions
143 lines (116 loc) · 2.57 KB
/
Request.php
File metadata and controls
143 lines (116 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php declare(strict_types = 1);
namespace Contributte\Codeception\Http;
use Exception;
use Nette\Http\FileUpload;
use Nette\Http\IRequest;
use Nette\Http\RequestFactory;
use Nette\Http\UrlScript;
/**
* HttpRequest class for tests.
*/
class Request implements IRequest
{
private RequestFactory $factory;
private IRequest $request;
public function __construct(RequestFactory $factory)
{
$this->factory = $factory;
$this->reset();
}
public function reset(): void
{
$this->request = $this->factory->fromGlobals();
}
public function getCookie(string $key): mixed
{
return $this->request->getCookie($key);
}
/**
* @return mixed[]
*/
public function getCookies(): array
{
return $this->request->getCookies();
}
public function getFile(string $key): ?FileUpload
{
return $this->request->getFile($key);
}
/**
* @return FileUpload[]
*/
public function getFiles(): array
{
return $this->request->getFiles();
}
public function getHeader(string $header): ?string
{
return $this->request->getHeader($header);
}
/**
* @return string[]
*/
public function getHeaders(): array
{
return $this->request->getHeaders();
}
public function getMethod(): string
{
return $this->request->getMethod();
}
public function getPost(?string $key = null): mixed
{
return func_num_args() === 0 ? $this->request->getPost() : $this->request->getPost($key);
}
public function getQuery(?string $key = null): mixed
{
return func_num_args() === 0 ? $this->request->getQuery() : $this->request->getQuery($key);
}
public function getRawBody(): ?string
{
return $this->request->getRawBody();
}
public function getRemoteAddress(): ?string
{
return $this->request->getRemoteAddress();
}
public function getRemoteHost(): ?string
{
return $this->request->getRemoteHost();
}
public function getUrl(): UrlScript
{
return $this->request->getUrl();
}
public function isAjax(): bool
{
return $this->request->isAjax();
}
public function isMethod(string $method): bool
{
return $this->request->isMethod($method);
}
public function isSecured(): bool
{
return $this->request->isSecured();
}
public function isSameSite(): bool
{
return true;
}
/**
* Returns basic HTTP authentication credentials.¨
*
* @return array{string, string}|null
*/
public function getBasicCredentials(): ?array
{
if (method_exists($this->request, 'getBasicCredentials')) {
return $this->request->getBasicCredentials();
}
throw new Exception(sprintf(
'getBasicCredentials() method is not available on %s.',
get_class($this->request),
));
}
}