1 | <?php |
||
25 | class Request { |
||
26 | protected $vars; |
||
27 | |||
28 | 18 | public function __construct($vars = []){ |
|
31 | |||
32 | /** |
||
33 | * Returns the request uri |
||
34 | * @return string |
||
35 | */ |
||
36 | public function getRequestUri() { |
||
39 | |||
40 | public function getServerProtocol() { |
||
59 | |||
60 | 5 | public function getHost(){ |
|
61 | 5 | $host = 'localhost'; |
|
62 | 5 | $forwardedHost = $this->server('HTTP_X_FORWARDED_HOST'); |
|
63 | 5 | if (!is_null($forwardedHost)) { |
|
64 | 3 | $host = $this->getPartBeforeComma($forwardedHost); |
|
65 | } else { |
||
66 | 2 | $httpHost = $this->server('HTTP_HOST'); |
|
67 | 2 | if (is_null($httpHost)) { |
|
68 | 1 | $serverName = $this->server('SERVER_NAME'); |
|
69 | 1 | if (!is_null($serverName)){ |
|
70 | 1 | $host = $serverName; |
|
71 | } |
||
72 | } else { |
||
73 | 1 | $host = $httpHost; |
|
74 | } |
||
75 | } |
||
76 | 5 | return $host; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param string $name |
||
81 | * @return mixed |
||
82 | */ |
||
83 | 4 | public function postParameter($name){ |
|
86 | |||
87 | /** |
||
88 | * @param string $name |
||
89 | * @return mixed |
||
90 | */ |
||
91 | 5 | public function header($name) { |
|
95 | |||
96 | /** |
||
97 | * @param string $name |
||
98 | * @return mixed |
||
99 | */ |
||
100 | 14 | public function server($name){ |
|
103 | |||
104 | /** |
||
105 | * Return first part before comma or the string itself if there is no comma |
||
106 | * @param string $str |
||
107 | * @return string |
||
108 | */ |
||
109 | 3 | private function getPartBeforeComma($str){ |
|
118 | |||
119 | } |
||
120 | |||
121 |