1 | <?php |
||
16 | class Request extends HttpFoundationRequest |
||
17 | { |
||
18 | |||
19 | protected $addr; |
||
20 | |||
21 | protected $protocol; |
||
22 | |||
23 | protected $body; |
||
24 | |||
25 | protected $connection; |
||
26 | |||
27 | public function getUserAgent() |
||
28 | { |
||
29 | $userAgent = $this->getHeader('User-Agent'); |
||
30 | return $userAgent ? $userAgent : ''; |
||
31 | } |
||
32 | |||
33 | public function getHeader($name) |
||
34 | { |
||
35 | return $this->headers->get($name); |
||
36 | } |
||
37 | |||
38 | public function getAllHeaders($ignore = array()) |
||
39 | { |
||
40 | $headers = array(); |
||
41 | foreach ($this->headers->all() as $name => $value) { |
||
42 | if (empty($ignore) || !in_array($name, $ignore)) { |
||
43 | $headers[$name] = $this->headers->get($name); |
||
44 | } |
||
45 | } |
||
46 | return $headers; |
||
47 | } |
||
48 | |||
49 | public function getHeaders() |
||
62 | |||
63 | public function getCookie($name) |
||
64 | { |
||
65 | return $this->cookies->get($name); |
||
66 | } |
||
67 | |||
68 | public function getCookies($names = array()) |
||
69 | { |
||
70 | $cookies = array(); |
||
71 | foreach ($this->cookies->all() as $name => $value) { |
||
72 | if (in_array($name, $names)) { |
||
73 | $cookies[$name] = $this->cookies->get($name); |
||
74 | } |
||
75 | } |
||
76 | return $cookies; |
||
77 | } |
||
78 | |||
79 | public function getAddr() |
||
87 | |||
88 | public function setAddr($addr) |
||
94 | |||
95 | /* |
||
96 | * @return string|null |
||
97 | */ |
||
98 | public function getProtocol() |
||
99 | { |
||
100 | if ($this->protocol) { |
||
101 | return $this->protocol; |
||
102 | } |
||
103 | |||
104 | return $this->server->get('SERVER_PROTOCOL'); |
||
105 | } |
||
106 | |||
107 | /* |
||
108 | * @param string |
||
109 | */ |
||
110 | public function setProtocol($protocol) |
||
111 | { |
||
112 | $this->protocol = $protocol; |
||
113 | |||
114 | return $this; |
||
115 | } |
||
116 | |||
117 | /* |
||
118 | * @return string|null |
||
119 | */ |
||
120 | public function getConnection() |
||
121 | { |
||
122 | if ($this->connection) { |
||
123 | return $this->connection; |
||
124 | } |
||
125 | |||
126 | return $this->headers->get('connection'); |
||
|
|||
127 | } |
||
128 | |||
129 | /* |
||
130 | * @param string |
||
131 | */ |
||
132 | public function setConnection($connection) |
||
133 | { |
||
134 | $this->connection = $connection; |
||
135 | |||
136 | return $this; |
||
137 | } |
||
138 | |||
139 | /* |
||
140 | * @return string|null |
||
141 | */ |
||
142 | public function getBody() |
||
148 | |||
149 | /* |
||
150 | * @param string |
||
151 | */ |
||
152 | public function setBody($body) |
||
158 | |||
159 | public function __toString() |
||
163 | |||
164 | public function toArray() |
||
165 | { |
||
166 | $request = array(); |
||
167 | |||
168 | $request['scheme'] = $this->getScheme(); |
||
169 | $request['method'] = $this->getMethod(); |
||
170 | $request['host'] = $this->getHost(); |
||
171 | $request['port'] = $this->getPort(); |
||
172 | $request['url'] = $this->getRequestUri(); |
||
187 | |||
188 | } |
||
189 |