1 | <?php |
||
10 | trait Server { |
||
11 | /** |
||
12 | * Language accepted by client, `''` by default |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | public $language; |
||
17 | /** |
||
18 | * Version accepted by client, will match `/^[0-9\.]+$/`, useful for API, `1` by default |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | public $version; |
||
23 | /** |
||
24 | * Content type, `''` by default |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | public $content_type; |
||
29 | /** |
||
30 | * Do not track |
||
31 | * |
||
32 | * @var bool |
||
33 | */ |
||
34 | public $dnt; |
||
35 | /** |
||
36 | * The best guessed host |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | public $host; |
||
41 | /** |
||
42 | * The best guessed IP of client (based on all known headers), `$this->remote_addr` by default |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | public $ip; |
||
47 | /** |
||
48 | * Schema `http` or `https` |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | public $schema; |
||
53 | /** |
||
54 | * Protocol, for instance: `HTTP/1.0`, `HTTP/1.1` (default), HTTP/2.0 |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | public $protocol; |
||
59 | /** |
||
60 | * Query string |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | public $query_string; |
||
65 | /** |
||
66 | * HTTP referer, `''` by default |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | public $referer; |
||
71 | /** |
||
72 | * Where request came from, not necessary real IP of client, `127.0.0.1` by default |
||
73 | * |
||
74 | * @var string |
||
75 | */ |
||
76 | public $remote_addr; |
||
77 | /** |
||
78 | * Path |
||
79 | * |
||
80 | * @var string |
||
81 | */ |
||
82 | public $path; |
||
83 | /** |
||
84 | * URI |
||
85 | * |
||
86 | * @var string |
||
87 | */ |
||
88 | public $uri; |
||
89 | /** |
||
90 | * Uppercase method, GET by default |
||
91 | * |
||
92 | * @var string |
||
93 | */ |
||
94 | public $method; |
||
95 | /** |
||
96 | * Is requested with HTTPS |
||
97 | * |
||
98 | * @var bool |
||
99 | */ |
||
100 | public $secure; |
||
101 | /** |
||
102 | * User agent |
||
103 | * |
||
104 | * @var string |
||
105 | */ |
||
106 | public $user_agent; |
||
107 | /** |
||
108 | * Headers are normalized to lowercase keys with hyphen as separator, for instance: `connection`, `referer`, `content-type`, `accept-language` |
||
109 | * |
||
110 | * @var string[] |
||
111 | */ |
||
112 | public $headers; |
||
113 | /** |
||
114 | * @param string[] $server Typically `$_SERVER` |
||
115 | */ |
||
116 | function init_server ($server = []) { |
||
136 | /** |
||
137 | * @param string[] $server |
||
138 | */ |
||
139 | protected function fill_server_properties ($server) { |
||
157 | /** |
||
158 | * @param string[] $server |
||
159 | */ |
||
160 | protected function fill_headers ($server) { |
||
173 | /** |
||
174 | * The best guessed IP of client (based on all known headers), `127.0.0.1` by default |
||
175 | * |
||
176 | * @param string[] $server |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | protected function ip ($server) { |
||
199 | /** |
||
200 | * The best guessed host |
||
201 | * |
||
202 | * @param string[] $server |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | protected function host ($server) { |
||
234 | /** |
||
235 | * Secure protocol detection |
||
236 | * |
||
237 | * @param array $server |
||
238 | * |
||
239 | * @return bool |
||
240 | */ |
||
241 | protected function secure ($server) { |
||
246 | /** |
||
247 | * Get header by name |
||
248 | * |
||
249 | * @param string $name |
||
250 | * |
||
251 | * @return false|string Header content if exists or `false` otherwise |
||
252 | */ |
||
253 | function header ($name) { |
||
256 | } |
||
257 |