Source of file Request.php

Size: 8,567 Bytes - Last Modified: 2016-01-10T08:00:01-05:00

../src/Request.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
70
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
71
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
72
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
73
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
74
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
75
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
76
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
7778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
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"
114
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"
115
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"
116
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"
117
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"
118119120
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"
121
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"
122
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"
123124
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"
125
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"
126
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"
127
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"
128129
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"
130
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"
131
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"
132133
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"
134135136137138139140141142143144145146
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"
147
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"
148149150151152153154155156157158159
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"
160161
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"
162
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"
163
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
164
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
165
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
166167
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"
168
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"
169170171
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"
172
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"
173
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"
174
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"
175
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"
176
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"
177
Covered by 2 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
178
Covered by 2 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
179
Covered by 2 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
180
Covered by 2 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
181
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
182
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
183
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
184
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "tricky test"
185186187
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
188
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
189
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
190
Covered by 1 test(s):
  • MvcLite\RequestTest::testBuildFromString with data set "simple test"
191192
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"
193194195196197198199200201202203
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
204205
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
206207208209210211212213214215
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
216217
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
218
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
219
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
220
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
221
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
222223
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParams
224225226227228229230231232233234
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
235
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetParam
236237
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"
238239240241242243244245246247248
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
249250
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
251252253254255256257258259260261
Covered by 1 test(s):
  • MvcLite\RequestTest::testIsPost
262
Covered by 1 test(s):
  • MvcLite\RequestTest::testIsPost
263264265
Covered by 1 test(s):
  • MvcLite\RequestTest::testIsPost
266267268269270271272273274275
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetHeaders with data set "simple test"
276277278279280281282283284285
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"
286287288289290291292293294295296
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
297
Covered by 1 test(s):
  • MvcLite\RequestTest::testIsAjax
298299300
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
301302303304305306307308309310
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetUri
311312313314315316317318319320
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"
321
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"
322
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"
323
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
324
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
325
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
326
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
327328
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"
329
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
330331332
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"
333334335336337338339340341342343344345
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"
346
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"
347
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"
348
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"
349
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"
350
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"
351
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"
352353
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"
354
Covered by 1 test(s):
  • MvcLite\RequestTest::testGetFormat with data set "bad content type, expect exception"
355356357
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"
358359360
<?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';

    /**
     * Holder for the request method.
     *
     * @var string
     */
    protected $method = 'get';

    /**
     * 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']));
        $this->setMethod($_SERVER);
    }

    /**
     * Setter for the $method property.
     *
     * @param string $method The request method.
     *
     * @return MvcList\Request Returns $this, for object-chaining.
     */
    public function setMethod($method)
    {
        if (is_array($method)) {
            $method = $method['REQUEST_METHOD'];
        }
        $this->method = $method;
        return $this;
    }

    /**
     * Getter for the method property.
     *
     * @return string The request method.
     */
    public function getMethod()
    {
        return $this->method;
    }

    /**
     *
     * 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];
    }
}