1 | <?php |
||
13 | class Request |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var string Full URL |
||
18 | */ |
||
19 | protected $url; |
||
20 | |||
21 | /** |
||
22 | * @var array POST data |
||
23 | */ |
||
24 | protected $post; |
||
25 | |||
26 | /** |
||
27 | * @var Cookie Cookie |
||
28 | */ |
||
29 | protected $cookie; |
||
30 | |||
31 | /** |
||
32 | * Request constructor. |
||
33 | * |
||
34 | * @param array $server |
||
35 | * @param array $post |
||
36 | * @param Cookie $cookie |
||
37 | */ |
||
38 | public function __construct(Cookie $cookie, array $server = [], array $post = []) |
||
39 | { |
||
40 | $this->url = $this->createUrlFromServerArray($server, !empty($server['HTTPS'])); |
||
41 | $this->post = $post; |
||
42 | $this->cookie = $cookie; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Get request URL path |
||
47 | * |
||
48 | * @return string URL path |
||
49 | */ |
||
50 | public function getPath(): string |
||
51 | { |
||
52 | $path = parse_url($this->url, PHP_URL_PATH); |
||
53 | |||
54 | if (is_string($path) === false) { |
||
55 | $path = ''; |
||
56 | } |
||
57 | |||
58 | return $path; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Get request POST data |
||
63 | * |
||
64 | * @return array POST data |
||
65 | */ |
||
66 | public function getPost(): array |
||
67 | { |
||
68 | return $this->post; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Get cookie |
||
73 | * |
||
74 | * @return Cookie |
||
75 | */ |
||
76 | public function getCookie(): Cookie |
||
77 | { |
||
78 | return $this->cookie; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Create URL from _SERVER array |
||
83 | * |
||
84 | * @param array $server _SERVER array |
||
85 | * @param bool $secure |
||
86 | * |
||
87 | * @return string URL |
||
88 | */ |
||
89 | protected function createUrlFromServerArray(array $server, bool $secure = true): string |
||
99 | } |
||
100 |