1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_input\Simplified; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use ArrayAccess; |
7
|
|
|
use kalanis\kw_input\InputException; |
8
|
|
|
use kalanis\kw_input\Parsers\FixServer; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ServerAdapter |
13
|
|
|
* @package kalanis\kw_input\Extras |
14
|
|
|
* Accessing _SERVER via ArrayAccess |
15
|
|
|
* @property string $PHP_SELF |
16
|
|
|
* @property string $argv |
17
|
|
|
* @property string $argc |
18
|
|
|
* @property string $GATEWAY_INTERFACE |
19
|
|
|
* @property string $SERVER_ADDR |
20
|
|
|
* @property string $SERVER_NAME |
21
|
|
|
* @property string $SERVER_SOFTWARE |
22
|
|
|
* @property string $SERVER_PROTOCOL |
23
|
|
|
* @property string $REQUEST_METHOD |
24
|
|
|
* @property string $REQUEST_TIME |
25
|
|
|
* @property string $REQUEST_TIME_FLOAT |
26
|
|
|
* @property string $QUERY_STRING |
27
|
|
|
* @property string $DOCUMENT_ROOT |
28
|
|
|
* @property string $HTTP_ACCEPT |
29
|
|
|
* @property string $HTTP_ACCEPT_CHARSET |
30
|
|
|
* @property string $HTTP_ACCEPT_ENCODING |
31
|
|
|
* @property string $HTTP_ACCEPT_LANGUAGE |
32
|
|
|
* @property string $HTTP_CONNECTION |
33
|
|
|
* @property string $HTTP_HOST |
34
|
|
|
* @property string $HTTP_REFERER |
35
|
|
|
* @property string $HTTP_USER_AGENT |
36
|
|
|
* @property string $HTTPS |
37
|
|
|
* @property string $REMOTE_ADDR |
38
|
|
|
* @property string $REMOTE_HOST |
39
|
|
|
* @property string $REMOTE_PORT |
40
|
|
|
* @property string $SCRIPT_FILENAME |
41
|
|
|
* @property string $SERVER_ADMIN |
42
|
|
|
* @property string $SERVER_PORT |
43
|
|
|
* @property string $SERVER_SIGNATURE |
44
|
|
|
* @property string $PATH_TRANSLATED |
45
|
|
|
* @property string $SCRIPT_NAME |
46
|
|
|
* @property string $REQUEST_URI |
47
|
|
|
* @property string $PHP_AUTH_DIGEST |
48
|
|
|
* @property string $PHP_AUTH_USER |
49
|
|
|
* @property string $PHP_AUTH_PW |
50
|
|
|
* @property string $AUTH_TYPE |
51
|
|
|
* @property string $PATH_INFO |
52
|
|
|
* @property string $ORIG_PATH_INFO |
53
|
|
|
*/ |
54
|
|
|
class ServerAdapter implements ArrayAccess |
55
|
|
|
{ |
56
|
|
|
use TNullBytes; |
57
|
|
|
|
58
|
|
|
/** @var array<string|int, string|int|bool|null> */ |
59
|
|
|
protected $server = []; |
60
|
|
|
|
61
|
3 |
|
public final function __construct() |
62
|
|
|
{ |
63
|
3 |
|
$this->server = FixServer::updateAuth(FixServer::updateVars($_SERVER)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string|int $offset |
68
|
|
|
* @return mixed |
69
|
|
|
*/ |
70
|
1 |
|
public final function __get($offset) |
71
|
|
|
{ |
72
|
1 |
|
return $this->offsetGet($offset); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $offset |
77
|
|
|
* @param mixed|null $value |
78
|
|
|
* @throws InputException |
79
|
|
|
*/ |
80
|
1 |
|
public final function __set($offset, $value): void |
81
|
|
|
{ |
82
|
1 |
|
$this->offsetSet($offset, $value); |
83
|
|
|
// @codeCoverageIgnoreStart |
84
|
|
|
} |
85
|
|
|
// @codeCoverageIgnoreEnd |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $offset |
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
1 |
|
public final function __isset($offset): bool |
92
|
|
|
{ |
93
|
1 |
|
return $this->offsetExists($offset); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $offset |
98
|
|
|
* @throws InputException |
99
|
|
|
*/ |
100
|
1 |
|
public final function __unset($offset): void |
101
|
|
|
{ |
102
|
1 |
|
$this->offsetUnset($offset); |
103
|
|
|
// @codeCoverageIgnoreStart |
104
|
|
|
} |
105
|
|
|
// @codeCoverageIgnoreEnd |
106
|
|
|
|
107
|
1 |
|
public final function offsetExists($offset): bool |
108
|
|
|
{ |
109
|
1 |
|
return isset($this->server[$this->removeNullBytes(strval($offset))]); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
#[\ReturnTypeWillChange] |
113
|
1 |
|
public final function offsetGet($offset) |
114
|
|
|
{ |
115
|
1 |
|
return $this->server[$this->removeNullBytes(strval($offset))]; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param mixed $offset |
120
|
|
|
* @param mixed $value |
121
|
|
|
* @throws InputException |
122
|
|
|
*/ |
123
|
1 |
|
public final function offsetSet($offset, $value): void |
124
|
|
|
{ |
125
|
1 |
|
throw new InputException('Cannot write into _SERVER variable'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param mixed $offset |
130
|
|
|
* @throws InputException |
131
|
|
|
*/ |
132
|
1 |
|
public final function offsetUnset($offset): void |
133
|
|
|
{ |
134
|
1 |
|
throw new InputException('Cannot write into _SERVER variable'); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|