1 | <?php |
||
30 | class Request { |
||
31 | protected $vars; |
||
32 | |||
33 | /** |
||
34 | * Request constructor. |
||
35 | * |
||
36 | * @param array $vars |
||
37 | */ |
||
38 | 18 | public function __construct($vars = []){ |
|
41 | |||
42 | /** |
||
43 | * Returns the request uri |
||
44 | * @return string |
||
45 | */ |
||
46 | public function getRequestUri() { |
||
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getServerProtocol() { |
||
72 | |||
73 | /** |
||
74 | * @return mixed|string |
||
75 | */ |
||
76 | 5 | public function getHost(){ |
|
77 | 5 | $host = 'localhost'; |
|
78 | 5 | $forwardedHost = $this->server('HTTP_X_FORWARDED_HOST'); |
|
79 | 5 | if (!is_null($forwardedHost)) { |
|
80 | 3 | $host = $this->getPartBeforeComma($forwardedHost); |
|
81 | } else { |
||
82 | 2 | $httpHost = $this->server('HTTP_HOST'); |
|
83 | 2 | if (is_null($httpHost)) { |
|
84 | 1 | $serverName = $this->server('SERVER_NAME'); |
|
85 | 1 | if (!is_null($serverName)){ |
|
86 | 1 | $host = $serverName; |
|
87 | } |
||
88 | } else { |
||
89 | 1 | $host = $httpHost; |
|
90 | } |
||
91 | } |
||
92 | 5 | return $host; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * @param string $name |
||
97 | * @return mixed |
||
98 | */ |
||
99 | 4 | public function postParameter($name){ |
|
102 | |||
103 | /** |
||
104 | * @param string $name |
||
105 | * @return mixed |
||
106 | */ |
||
107 | 5 | public function header($name) { |
|
111 | |||
112 | /** |
||
113 | * @param string $name |
||
114 | * @return mixed |
||
115 | */ |
||
116 | 14 | public function server($name){ |
|
119 | |||
120 | /** |
||
121 | * Return first part before comma or the string itself if there is no comma |
||
122 | * @param string $str |
||
123 | * @return string |
||
124 | */ |
||
125 | 3 | private function getPartBeforeComma($str){ |
|
134 | |||
135 | } |
||
136 | |||
137 |