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