@@ -35,7 +35,7 @@ final class HttpRequest
35
35
// all other sh1t
36
36
private $ attached = array ();
37
37
38
- private $ headers = array () ;
38
+ private $ headers = null ;
39
39
40
40
/**
41
41
* @var HttpMethod
@@ -47,7 +47,6 @@ final class HttpRequest
47
47
*/
48
48
private $ url = null ;
49
49
50
- //for CurlHttpClient if you need to send raw CURLOPT_POSTFIELDS
51
50
private $ body = null ;
52
51
53
52
/**
@@ -74,9 +73,12 @@ public static function createFromGlobals()
74
73
if (isset ($ _SESSION ))
75
74
$ request ->setSession ($ _SESSION );
76
75
77
- foreach ($ _SERVER as $ name => $ value )
78
- if (substr ($ name , 0 , 5 ) === 'HTTP_ ' )
79
- $ request ->setHeaderVar (substr ($ name , 5 ), $ value );
76
+ foreach ($ _SERVER as $ name => $ value ) {
77
+ if (strpos ($ name , 'HTTP_ ' ) === 0 ) {
78
+ $ name = str_replace ('_ ' , '- ' , substr ($ name , 5 ));
79
+ $ request ->setHeaderVar ($ name , $ value );
80
+ }
81
+ }
80
82
81
83
if (
82
84
$ request ->hasServerVar ('CONTENT_TYPE ' )
@@ -86,6 +88,11 @@ public static function createFromGlobals()
86
88
87
89
return $ request ;
88
90
}
91
+
92
+ public function __construct ()
93
+ {
94
+ $ this ->headers = new HttpHeaderCollection ();
95
+ }
89
96
90
97
public function &getGet ()
91
98
{
@@ -218,7 +225,11 @@ public function &getSession()
218
225
{
219
226
return $ this ->session ;
220
227
}
221
-
228
+
229
+ /**
230
+ * @param string $name
231
+ * @return mixed
232
+ */
222
233
public function getSessionVar ($ name )
223
234
{
224
235
return $ this ->session [$ name ];
@@ -278,7 +289,11 @@ public function &getAttached()
278
289
{
279
290
return $ this ->attached ;
280
291
}
281
-
292
+
293
+ /**
294
+ * @param string $name
295
+ * @return mixed
296
+ */
282
297
public function getAttachedVar ($ name )
283
298
{
284
299
return $ this ->attached [$ name ];
@@ -306,7 +321,7 @@ public function getByType(RequestType $type)
306
321
307
322
public function getHeaderList ()
308
323
{
309
- return $ this ->headers ;
324
+ return $ this ->headers -> getAll () ;
310
325
}
311
326
312
327
public function hasHeaderVar ($ name )
@@ -316,7 +331,7 @@ public function hasHeaderVar($name)
316
331
317
332
public function getHeaderVar ($ name )
318
333
{
319
- return $ this ->headers [ $ name] ;
334
+ return $ this ->headers -> get ( $ name) ;
320
335
}
321
336
322
337
/**
@@ -333,7 +348,7 @@ public function unsetHeaderVar($name)
333
348
**/
334
349
public function setHeaderVar ($ name , $ var )
335
350
{
336
- $ this ->headers [ $ name] = $ var ;
351
+ $ this ->headers -> set ( $ name, $ var) ;
337
352
return $ this ;
338
353
}
339
354
@@ -342,7 +357,7 @@ public function setHeaderVar($name, $var)
342
357
**/
343
358
public function setHeaders (array $ headers )
344
359
{
345
- $ this ->headers = $ headers ;
360
+ $ this ->headers = new HttpHeaderCollection ( $ headers) ;
346
361
return $ this ;
347
362
}
348
363
0 commit comments