Source of file Request.php

Size: 7,855 Bytes - Last Modified: 2015-12-22T09:12:14-05:00

../src/Request.php

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
63
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
64
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
65
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
66
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
67
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
68
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
6970717273747576777879
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
80
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
81
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
82
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
83
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
848586
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
87
Covered by 6 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
88
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
8990
Covered by 3 test(s):
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
91
Covered by 3 test(s):
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
92
Covered by 3 test(s):
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
93
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
9495
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
96
Covered by 2 test(s):
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
97
Covered by 2 test(s):
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
9899
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
100101102103104105106107108109110111112
Covered by 3 test(s):
  • MvcLite\RequestTest::testSetHeader
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
113
Covered by 3 test(s):
  • MvcLite\RequestTest::testSetHeader
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
114115116117118119120121122123124125
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
126127
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
128
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
129
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
130
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
131
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
132133
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
134
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
135136137
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
138
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
139
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
140
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
141
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
142
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
143
Covered by 2 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
144
Covered by 2 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
145
Covered by 2 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
146
Covered by 2 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
147
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
148
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
149
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
150
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
151152153
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
154
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
155
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
156
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
157158
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
159160161162163164165166167168169
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetParams
  • MvcLite\RequestTest::testGetParam
170171
Covered by 4 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetParams
  • MvcLite\RequestTest::testGetParam
172173174175176177178179180181
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
182183
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
184
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
185
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
186
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
187
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
188189
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
190191192193194195196197198199200
Covered by 4 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetParam
201
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParam
202203
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
204205206207208209210211212213214
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
215216
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
217218219220221222223224225226227
Covered by 1 test(s):
  • MvcLite\RequestTest::testIsPost
228
Covered by 1 test(s):
  • MvcLite\RequestTest::testIsPost
229230231
Covered by 1 test(s):
  • MvcLite\RequestTest::testIsPost
232233234235236237238239240241
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetHeaders with data set "simple test"
242243244245246247248249250251
Covered by 7 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testIsAjax
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
252253254255256257258259260261262
Covered by 4 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testIsAjax
263
Covered by 1 test(s):
  • MvcLite\RequestTest::testIsAjax
264265266
Covered by 4 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testIsAjax
267268269270271272273274275276
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetUri
277278279280281282283284285286
Covered by 5 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
287
Covered by 5 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
288
Covered by 5 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
289
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
290
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
291
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
292
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
293294
Covered by 5 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
295
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
296297298
Covered by 3 test(s):
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
299300301302303304305306307308309310311
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetFormat with data set "application/json"
  • MvcLite\RequestTest::testGetFormat with data set "application/javascript"
  • MvcLite\RequestTest::testGetFormat with data set "text/html"
  • MvcLite\RequestTest::testGetFormat with data set "text/plain"
  • MvcLite\RequestTest::testGetFormat with data set "text/csv"
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
312
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetFormat with data set "application/json"
  • MvcLite\RequestTest::testGetFormat with data set "application/javascript"
  • MvcLite\RequestTest::testGetFormat with data set "text/html"
  • MvcLite\RequestTest::testGetFormat with data set "text/plain"
  • MvcLite\RequestTest::testGetFormat with data set "text/csv"
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
313
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetFormat with data set "application/json"
  • MvcLite\RequestTest::testGetFormat with data set "application/javascript"
  • MvcLite\RequestTest::testGetFormat with data set "text/html"
  • MvcLite\RequestTest::testGetFormat with data set "text/plain"
  • MvcLite\RequestTest::testGetFormat with data set "text/csv"
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
314
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetFormat with data set "application/json"
  • MvcLite\RequestTest::testGetFormat with data set "application/javascript"
  • MvcLite\RequestTest::testGetFormat with data set "text/html"
  • MvcLite\RequestTest::testGetFormat with data set "text/plain"
  • MvcLite\RequestTest::testGetFormat with data set "text/csv"
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
315
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetFormat with data set "application/json"
  • MvcLite\RequestTest::testGetFormat with data set "application/javascript"
  • MvcLite\RequestTest::testGetFormat with data set "text/html"
  • MvcLite\RequestTest::testGetFormat with data set "text/plain"
  • MvcLite\RequestTest::testGetFormat with data set "text/csv"
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
316
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetFormat with data set "application/json"
  • MvcLite\RequestTest::testGetFormat with data set "application/javascript"
  • MvcLite\RequestTest::testGetFormat with data set "text/html"
  • MvcLite\RequestTest::testGetFormat with data set "text/plain"
  • MvcLite\RequestTest::testGetFormat with data set "text/csv"
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
317
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetFormat with data set "application/json"
  • MvcLite\RequestTest::testGetFormat with data set "application/javascript"
  • MvcLite\RequestTest::testGetFormat with data set "text/html"
  • MvcLite\RequestTest::testGetFormat with data set "text/plain"
  • MvcLite\RequestTest::testGetFormat with data set "text/csv"
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
318319
Covered by 8 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetFormat with data set "application/json"
  • MvcLite\RequestTest::testGetFormat with data set "application/javascript"
  • MvcLite\RequestTest::testGetFormat with data set "text/html"
  • MvcLite\RequestTest::testGetFormat with data set "text/plain"
  • MvcLite\RequestTest::testGetFormat with data set "text/csv"
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
320
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
321322323
Covered by 7 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\RequestTest::testGetFormat with data set "application/json"
  • MvcLite\RequestTest::testGetFormat with data set "application/javascript"
  • MvcLite\RequestTest::testGetFormat with data set "text/html"
  • MvcLite\RequestTest::testGetFormat with data set "text/plain"
  • MvcLite\RequestTest::testGetFormat with data set "text/csv"
324325326
<?php
/**
 * Base Request
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  Request
 * @since       File available since release 1.0.1
 * @author      Cory Collier <corycollier@corycollier.com>
 */

namespace MvcLite;

use MvcLite\Traits\Singleton as SingletonTrait;
use MvcLite\Traits\FilterChain as FilterChainTrait;

/**
 * Base Request
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  Request
 * @since       Class available since release 1.0.1
 * @author      Cory Collier <corycollier@corycollier.com>
 */
class Request extends ObjectAbstract
{
    use SingletonTrait;
    use FilterChainTrait;

    /**
     * Constants
     */
    const ERR_BAD_CONTENT_TYPE = 'Content type [%s] not recognized';

    /**
     * associative array representing the request params
     *
     * @var array
     */
    protected $params = [];

    /**
     * associative array of the headers sent from the client
     *
     * @var array
     */
    protected $headers = [];

    /**
     * stores the original request uri
     *
     * @var string
     */
    protected $uri;

    /**
     * method to start the request up
     */
    public function init()
    {
        $this->uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
        $this->params = array_merge($this->params, $_COOKIE);
        $this->params = array_merge($this->params, $_POST);
        $this->params = array_merge($this->params, $_GET);
        $this->setHeaders($_SERVER);
        $this->setParams($this->buildFromString(@$_GET['q']));
    }

    /**
     *
     * Method to set the headers.
     *
     * @return MvcLite\Request Returns $this, for object-chaining.
     */
    public function setHeaders($headers = [])
    {
        // Create the filter chain to transform _SERVER to headers.
        $filter = $this->getFilterChain([
            'UnderscoreToDash',
            'StringtoLower',
        ]);
        $filter->addFilter(new Filter\SeparatorToUcwords('-'));

        // iterate over the $_SERVER superglobal values.
        foreach ($headers as $key => $value) {
            if (substr($key, 0, 5) != 'HTTP_') {
                continue;
            }
            $key = $filter->filter($key);
            $key = strtr($key, ['Http-' => '']);
            $this->setHeader($key, $value);
        }

        if (isset($headers['CONTENT_TYPE'])) {
            $this->setHeader('Content-Type', $headers['CONTENT_TYPE']);
        }

        return $this;
    }

    /**
     * Sets a single header
     *
     * @param string $name The name of the header to set.
     * @param string $value The value of the header.
     *
     * @return MvcLite\Request Returns $this, for object-chaining.
     */
    public function setHeader($name, $value)
    {
        $this->headers[$name] = $value;
        return $this;
    }

    /**
     * Build an associative array from a string
     *
     * @param string $string
     * @param string $separator
     * @return array
     */
    public function buildFromString($string = '', $separator = '/')
    {
        global $argv;
        // create a list of parts by separator
        $parts = array_filter(explode($separator, $string));
        if (!$parts && PHP_SAPI == 'cli') {
            $parts = $argv;
            array_shift($parts);
        }

        $controller = array_shift($parts);
        $action = array_shift($parts);

        $results = [
            'controller' => $controller ? $controller : 'index',
            'action'     => $action ? $action : 'index',
        ];
        $length = count($parts);
        $i = 0;
        while ($i < $length) {
            if (array_key_exists($i + 1, $parts)) {
                $key = $parts[$i];
                $value = $parts[$i + 1];
                if (in_array($key, ['controller', 'action'])) {
                    if ($i <= 2) {
                        $i = $i + 2;
                    }
                    continue;
                }

                $results[$key] = $value;
            }
            $i = $i + 2;
        }

        return $results;
    }

    /**
     * setter for the params property
     *
     * @param $params
     * @return Request $this for object-chaining.
     */
    public function setParams($params = [])
    {
        $this->params = array_merge($this->params, (array)$params);

        return $this;
    }

    /**
     * getter for the params property
     *
     * @return array All of the request params (_GET, _POST, and _COOKIE)
     */
    public function getParams()
    {
        $params = $this->params;

        foreach ($params as $key => $value) {
            if (! $key || ! $value || $key === 'q') {
                unset($params[$key]);
            }
        }

        return $params;
    }

    /**
     * Gets a single param from the params array
     *
     * @param string $param
     * @return string
     */
    public function getParam($param)
    {
        if (array_key_exists($param, $this->params)) {
            return $this->params[$param];
        }
    }

    /**
     * method to set a param manually
     *
     * @param string $param
     * @param string $value
     * @return Request $this for object-chaining.
     */
    public function setParam($param, $value = '')
    {
        $this->params[$param] = $value;

        return $this;
    }

    /**
     * Determines if the request is post or not
     *
     * @return boolean
     */
    public function isPost()
    {
        // if there is data in the _post property, return true
        if (count($_POST)) {
            return true;
        }

        return false;
    }

    /**
     * getter for the headers property
     *
     * @return array
     */
    public function getHeaders()
    {
        return $this->headers;
    }

    /**
     * method to get the value for a single header
     *
     * @param string $header
     */
    public function getHeader($header = '')
    {
        return @$this->headers[$header];
    }

    /**
     * Method to indicate whether the current request is AJAX or not
     *
     * @return boolean
     */
    public function isAjax()
    {
        // if the request is ajax, don't load the layout
        if ($this->getHeader('X-Requested-With') == 'XMLHttpRequest') {
            return true;
        }

        return false;
    }

    /**
     * getter for the uri value
     *
     * @return string
     */
    public function getUri()
    {
        return $this->uri;
    }

    /**
     * Getter for the content type of the request.
     *
     * @return string The content type.
     */
    public function getContentType()
    {
        $contentType = $this->getHeader('Content-Type');
        $contentType = trim(explode(';', $contentType)[0]);
        if (! $contentType) {
            $accept = $this->getHeader('Accept');
            $parts = explode(',', $accept);
            $contentType = $parts[0];
        }

        if (! $contentType && PHP_SAPI == 'cli') {
            return 'text/plain';
        }

        return $contentType ? $contentType : 'text/html';
    }

    /**
     * Gets a friendly version of the format.
     *
     * @param string $contentType The raw content type.
     *
     * @return string The machine friendly name for the request type (aka Format).
     */
    public function getFormat($contentType)
    {
        $map = [
            'application/json'       => 'json',
            'application/javascript' => 'json',
            'text/html'              => 'html',
            'text/plain'             => 'text',
            'text/csv'               => 'csv',
            '*/*'                    => 'json',
        ];

        if (!array_key_exists($contentType, $map)) {
            throw new Exception(sprintf(self::ERR_BAD_CONTENT_TYPE, $contentType));
        }

        return $map[$contentType];
    }
}