55class Request
66{
77 protected $ serverRequest ;
8- protected $ dataMap ;
9-
8+ protected $ dataMap = array ();
109 protected $ dataMethods = array (
1110 'query ' => 'getQueryParams ' ,
1211 'data ' => 'getParsedBody ' ,
1312 'attributes ' => 'getAttributes ' ,
13+ 'uploads ' => 'getFileUploads ' ,
1414 );
1515
16- public function __construct ($ serverRequest )
16+ protected $ server ;
17+ protected $ headers ;
18+
19+ public function __construct ($ builder , $ serverRequest )
1720 {
18- $ this ->serverRequest = $ serverRequest ;
21+ $ this ->builder = $ builder ;
22+ $ this ->serverRequest = $ serverRequest ;
1923 }
2024
2125 public function query ()
2226 {
23- $ this ->getData ('query ' );
27+ return $ this ->getData ('query ' );
2428 }
2529
2630 public function data ()
2731 {
28- $ this ->getData ('data ' );
32+ return $ this ->getData ('data ' );
2933 }
3034
3135 public function attributes ()
3236 {
33- $ this ->getData ('attributes ' );
37+ return $ this ->getData ('attributes ' );
3438 }
3539
36- public function server ()
40+ public function uploads ()
3741 {
38-
42+ return $ this -> getData ( ' uploads ' );
3943 }
4044
41-
45+ public function server ()
46+ {
47+ if ($ this ->server === null ) {
48+ $ data = $ this ->serverRequest ->getServerParams ();
49+ $ this ->server = $ this ->builder ->serverData ($ data );
50+ }
51+
52+ return $ this ->server ;
53+ }
4254
43- public function header ( $ name , $ default = null )
55+ public function headers ( )
4456 {
45- return $ this ->serverRequest =?
57+ if ($ this ->headers === null ) {
58+ $ data = $ this ->serverRequest ->getHeaders ();
59+ $ this ->headers = $ this ->builder ->headers ($ data );
60+ }
61+
62+ return $ this ->headers ;
4663 }
4764
65+ public function serverRequest ()
66+ {
67+ return $ this ->serverRequest ;
68+ }
4869
49- protected f
50- public function url ()
70+ protected function getData ($ type )
5171 {
52- return $ this ->
72+ if (!array_key_exists ($ type , $ this ->dataMap )) {
73+ $ method = $ this ->dataMethods [$ type ];
74+ $ data = $ this ->serverRequest ->$ method ();
75+ $ this ->dataMap [$ type ] = $ this ->builder ->data ($ data );
76+ }
77+
78+ return $ this ->dataMap [$ type ];
5379 }
5480}
0 commit comments