1 | <?php |
||
10 | trait Server { |
||
11 | /** |
||
12 | * Uppercase method, GET by default |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | public $method; |
||
17 | /** |
||
18 | * The best guessed host |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | public $host; |
||
23 | /** |
||
24 | * Schema `http` or `https` |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | public $scheme; |
||
29 | /** |
||
30 | * Is requested with HTTPS |
||
31 | * |
||
32 | * @var bool |
||
33 | */ |
||
34 | public $secure; |
||
35 | /** |
||
36 | * Protocol, for instance: `HTTP/1.0`, `HTTP/1.1` (default), HTTP/2.0 |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | public $protocol; |
||
41 | /** |
||
42 | * Path |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | public $path; |
||
47 | /** |
||
48 | * URI, basically `$path?$query_string` (without `?` is query string is empty), `/` by default |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | public $uri; |
||
53 | /** |
||
54 | * Query string |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | public $query_string; |
||
59 | /** |
||
60 | * Headers are normalized to lowercase keys with hyphen as separator, for instance: `connection`, `referer`, `content-type`, `accept-language` |
||
61 | * |
||
62 | * @var string[] |
||
63 | */ |
||
64 | /** |
||
65 | * Where request came from, not necessary real IP of client, `127.0.0.1` by default |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | public $remote_addr; |
||
70 | /** |
||
71 | * The best guessed IP of client (based on all known headers), `$this->remote_addr` by default |
||
72 | * |
||
73 | * @var string |
||
74 | */ |
||
75 | public $ip; |
||
76 | public $headers; |
||
77 | /** |
||
78 | * @param string[] $server Typically `$_SERVER` |
||
79 | */ |
||
80 | function init_server ($server = []) { |
||
94 | /** |
||
95 | * @param string[] $server |
||
96 | */ |
||
97 | protected function fill_server_properties ($server) { |
||
109 | /** |
||
110 | * @param string[] $server |
||
111 | */ |
||
112 | protected function fill_headers ($server) { |
||
125 | /** |
||
126 | * The best guessed IP of client (based on all known headers), `127.0.0.1` by default |
||
127 | * |
||
128 | * @param string[] $server |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | protected function ip ($server) { |
||
151 | /** |
||
152 | * The best guessed host |
||
153 | * |
||
154 | * @param string[] $server |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | protected function host ($server) { |
||
186 | /** |
||
187 | * Secure protocol detection |
||
188 | * |
||
189 | * @param array $server |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | protected function secure ($server) { |
||
198 | /** |
||
199 | * Get header by name |
||
200 | * |
||
201 | * @param string $name |
||
202 | * |
||
203 | * @return string Header content if exists or `false` otherwise |
||
204 | */ |
||
205 | function header ($name) { |
||
208 | } |
||
209 |