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