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 | * Where request came from, not necessary real IP of client, `127.0.0.1` by default |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | public $remote_addr; |
||
65 | /** |
||
66 | * The best guessed IP of client (based on all known headers), `$this->remote_addr` by default |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | public $ip; |
||
71 | /** |
||
72 | * Headers are normalized to lowercase keys with hyphen as separator, for instance: `connection`, `referer`, `content-type`, `accept-language` |
||
73 | * |
||
74 | * @var string[] |
||
75 | */ |
||
76 | public $headers; |
||
77 | /** |
||
78 | * @var bool |
||
79 | */ |
||
80 | protected $cli; |
||
81 | /** |
||
82 | * @var string[] |
||
83 | */ |
||
84 | public $forwarded; |
||
85 | /** |
||
86 | * @param string[] $server Typically `$_SERVER` |
||
87 | */ |
||
88 | 44 | function init_server ($server = []) { |
|
102 | /** |
||
103 | * @param string[] $server |
||
104 | */ |
||
105 | 44 | protected function fill_server_properties ($server) { |
|
122 | /** |
||
123 | * @param string[] $server |
||
124 | */ |
||
125 | 44 | protected function fill_headers ($server) { |
|
138 | /** |
||
139 | * Parse `Forwarded` header into `$this->forwarded` |
||
140 | */ |
||
141 | 44 | protected function parse_forwarded_header () { |
|
150 | /** |
||
151 | * The best guessed IP of client (based on all known headers), `127.0.0.1` by default |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | 44 | protected function ip () { |
|
173 | /** |
||
174 | * The best guessed host |
||
175 | * |
||
176 | * @param string[] $server |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | 44 | protected function host ($server) { |
|
203 | /** |
||
204 | * Secure protocol detection |
||
205 | * |
||
206 | * @param array $server |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | 44 | protected function secure ($server) { |
|
220 | /** |
||
221 | * Get header by name |
||
222 | * |
||
223 | * @param string $name Case-insensitive |
||
224 | * |
||
225 | * @return string Header content if exists or empty string otherwise |
||
226 | */ |
||
227 | 60 | function header ($name) { |
|
231 | } |
||
232 |