11<?php
22namespace Phly \Http ;
33
4- use ArrayAccess ;
54use InvalidArgumentException ;
65use Psr \Http \Message \IncomingRequestInterface ;
76
2524class IncomingRequest extends Request implements IncomingRequestInterface
2625{
2726 /**
28- * @var array|object
27+ * @var array
2928 */
30- private $ bodyParams = [];
29+ private $ attributes = [];
3130
3231 /**
33- * @var array|ArrayAccess
32+ * @var array
3433 */
35- private $ cookieParams ;
34+ private $ bodyParams = [] ;
3635
3736 /**
38- * @var array|ArrayAccess
37+ * @var array
3938 */
40- private $ fileParams ;
39+ private $ cookieParams ;
4140
4241 /**
43- * @var array|ArrayAccess
42+ * @var array
4443 */
45- private $ pathParams = [] ;
44+ private $ fileParams ;
4645
4746 /**
48- * @var array|ArrayAccess
47+ * @var array
4948 */
5049 private $ queryParams ;
5150
5251 /**
53- * @param string|\Psr\Http\Message\StreamableInterface|array $stream Stream representing message body.
54- * Alternately, this can be an array with keys for each of the possible arguments.
55- * @param array|ArrayAccess $cookieParams Deserialized cookies
56- * @param array|ArrayAccess $pathParams Variables matched from the URI path
57- * @param array|ArrayAccess $queryParams Deserialized query string arguments
58- * @param array|ArrayAccess $bodyParams Deserialized body parameters
59- * @param array|ArrayAccess $fileParams Upload file information; should be in PHP's $_FILES format
52+ * @param string|\Psr\Http\Message\StreamableInterface|array $stream
53+ * Stream representing message body. Alternately, this can be an
54+ * array with keys for each of the possible arguments.
55+ * @param array $cookieParams Deserialized cookies
56+ * @param array $attributes Attributes derived from the request
57+ * @param array $queryParams Deserialized query string arguments
58+ * @param array $bodyParams Deserialized body parameters
59+ * @param array $fileParams Upload file information; should be in PHP's $_FILES format
6060 * @return void
6161 */
6262 public function __construct (
6363 $ stream = 'php://input ' ,
64- $ cookieParams = [],
65- $ pathParams = [],
66- $ queryParams = [],
67- $ bodyParams = [],
68- $ fileParams = []
64+ array $ cookieParams = [],
65+ array $ attributes = [],
66+ array $ queryParams = [],
67+ array $ bodyParams = [],
68+ array $ fileParams = []
6969 ) {
7070 if (is_array ($ stream )) {
7171 if (isset ($ stream ['cookieParams ' ]) && empty ($ cookieParams )) {
7272 $ cookieParams = $ stream ['cookieParams ' ];
7373 }
74- if (isset ($ stream ['pathParams ' ]) && empty ($ pathParams )) {
75- $ pathParams = $ stream ['pathParams ' ];
74+ if (isset ($ stream ['attributes ' ]) && empty ($ attributes )) {
75+ $ attributes = $ stream ['attributes ' ];
7676 }
7777 if (isset ($ stream ['queryParams ' ]) && empty ($ queryParams )) {
7878 $ queryParams = $ stream ['queryParams ' ];
@@ -89,7 +89,7 @@ public function __construct(
8989
9090 parent ::__construct ($ stream );
9191 $ this ->setCookieParams ($ cookieParams );
92- $ this ->setPathParams ( $ pathParams );
92+ $ this ->setAttributes ( $ attributes );
9393 $ this ->setQueryParams ($ queryParams );
9494 $ this ->setBodyParams ($ bodyParams );
9595 $ this ->setFileParams ($ fileParams );
@@ -100,14 +100,7 @@ public function __construct(
100100 *
101101 * Retrieves cookies sent by the client to the server.
102102 *
103- * The assumption is these are injected during instantiation, typically
104- * from PHP's $_COOKIE superglobal, and should remain immutable over the
105- * course of the incoming request.
106- *
107- * The return value can be either an array or an object that acts like
108- * an array (e.g., implements ArrayAccess, or an ArrayObject).
109- *
110- * @return array|ArrayAccess
103+ * @return array
111104 */
112105 public function getCookieParams ()
113106 {
@@ -123,21 +116,10 @@ public function getCookieParams()
123116 * the original value, filter them, and re-inject into the incoming
124117 * request..
125118 *
126- * The value provided should be an array or array-like object
127- * (e.g., implements ArrayAccess, or an ArrayObject).
128- *
129- * @param array|ArrayAccess $cookies Cookie values/structs
130- *
131- * @return void
119+ * @param array $cookies Cookie values/structs
132120 */
133- public function setCookieParams ($ cookies )
121+ public function setCookieParams (array $ cookies )
134122 {
135- if (! is_array ($ cookies ) && ! $ cookies instanceof ArrayAccess) {
136- throw new InvalidArgumentException (
137- 'Cookies must be provided as either an array or ArrayAccess '
138- );
139- }
140-
141123 $ this ->cookieParams = $ cookies ;
142124 }
143125
@@ -150,10 +132,7 @@ public function setCookieParams($cookies)
150132 * from PHP's $_GET superglobal, and should remain immutable over the
151133 * course of the incoming request.
152134 *
153- * The return value can be either an array or an object that acts like
154- * an array (e.g., implements ArrayAccess, or an ArrayObject).
155- *
156- * @return array|ArrayAccess
135+ * @return array
157136 */
158137 public function getQueryParams ()
159138 {
@@ -165,16 +144,10 @@ public function getQueryParams()
165144 *
166145 * Internal method only.
167146 *
168- * @param array|ArrayAccess $queryParams
147+ * @param array $queryParams
169148 */
170- private function setQueryParams ($ queryParams )
149+ private function setQueryParams (array $ queryParams )
171150 {
172- if (! is_array ($ queryParams ) && ! $ queryParams instanceof ArrayAccess) {
173- throw new InvalidArgumentException (
174- 'Query string arguments must be provided as either an array or ArrayAccess '
175- );
176- }
177-
178151 $ this ->queryParams = $ queryParams ;
179152 }
180153
@@ -188,10 +161,7 @@ private function setQueryParams($queryParams)
188161 * from PHP's $_FILES superglobal, and should remain immutable over the
189162 * course of the incoming request.
190163 *
191- * The return value can be either an array or an object that acts like
192- * an array (e.g., implements ArrayAccess, or an ArrayObject).
193- *
194- * @return array|ArrayAccess Upload file(s) metadata, if any.
164+ * @return array Upload file(s) metadata, if any.
195165 */
196166 public function getFileParams ()
197167 {
@@ -203,32 +173,24 @@ public function getFileParams()
203173 *
204174 * Internal method only.
205175 *
206- * @param array|ArrayAccess $fileParams
176+ * @param array $fileParams
207177 */
208- private function setFileParams ($ fileParams )
178+ private function setFileParams (array $ fileParams )
209179 {
210- if (! is_array ($ fileParams ) && ! $ fileParams instanceof ArrayAccess) {
211- throw new InvalidArgumentException (
212- 'Files must be provided as either an array or ArrayAccess '
213- );
214- }
215-
216180 $ this ->fileParams = $ fileParams ;
217181 }
218182
219183 /**
220184 * Retrieve any parameters provided in the request body.
221185 *
222186 * If the request body can be deserialized, and if the deserialized values
223- * can be represented as an array or object , this method can be used to
187+ * can be represented as an array, this method can be used to
224188 * retrieve them.
225189 *
226190 * In other cases, the parent getBody() method should be used to retrieve
227191 * the body content.
228192 *
229- * @return array|object The deserialized body parameters, if any. These may
230- * be either an array or an object, though an array or
231- * array-like object is recommended.
193+ * @return array The deserialized body parameters, if any.
232194 */
233195 public function getBodyParams ()
234196 {
@@ -238,61 +200,42 @@ public function getBodyParams()
238200 /**
239201 * Set the request body parameters.
240202 *
241- * If the body content can be deserialized, the values obtained may then
203+ * If the body content can be deserialized as an array , the values obtained may then
242204 * be injected into the response using this method. This method will
243205 * typically be invoked by a factory marshaling request parameters.
244206 *
245- * @param array|object $values The deserialized body parameters, if any.
246- * These may be either an array or an object,
247- * though an array or array-like object is
248- * recommended.
249- *
250- * @return void
207+ * @param array $values The deserialized body parameters, if any.
251208 */
252- public function setBodyParams ($ values )
209+ public function setBodyParams (array $ values )
253210 {
254- if (! is_array ($ values ) && ! is_object ($ values )) {
255- throw new InvalidArgumentException (
256- 'Body parameters must be provided as either an array or an object '
257- );
258- }
259-
260211 $ this ->bodyParams = $ values ;
261212 }
262213
263214 /**
264- * Retrieve parameters matched during routing.
215+ * Retrieve attributes derived from the request
265216 *
266217 * If a router or similar is used to match against the path and/or request,
267218 * this method can be used to retrieve the results, so long as those
268- * results can be represented as an array or array-like object .
219+ * results can be represented as an array.
269220 *
270- * @return array|ArrayAccess Path parameters matched by routing
221+ * @return array Path parameters matched by routing
271222 */
272- public function getPathParams ()
223+ public function getAttributes ()
273224 {
274- return $ this ->pathParams ;
225+ return $ this ->attributes ;
275226 }
276227
277228 /**
278229 * Set parameters discovered by matching that path
279230 *
280231 * If a router or similar is used to match against the path and/or request,
281- * this method can be used to inject the request with the results , so long
282- * as those results can be represented as an array or array-like object .
232+ * this method can be used to inject them , so long as those
233+ * results can be represented as an array.
283234 *
284- * @param array|ArrayAccess $values Path parameters matched by routing
285- *
286- * @return void
235+ * @param array $values Path parameters matched by routing
287236 */
288- public function setPathParams (array $ values )
237+ public function setAttributes (array $ values )
289238 {
290- if (! is_array ($ values ) && ! $ values instanceof ArrayAccess) {
291- throw new InvalidArgumentException (
292- 'Path parameters must be provided as either an array or ArrayAccess '
293- );
294- }
295-
296- $ this ->pathParams = $ values ;
239+ $ this ->attributes = $ values ;
297240 }
298241}
0 commit comments