Skip to content

Commit 69ea52e

Browse files
committed
Body parameters are the parsed body.
Per conversations with @Crell, @ircmaxell, @pmjones, and several others, the body parameters are always the parsed body content; calling them out as such, and without the "parameters" verbiage, implies that parsing may create non-array values, which is exceptionally likely when working with API and/or non-form-encoded payloads. Moreover, the content will always be specific to the incoming request, so supporting one method representing POST and another representing parsed content is redundant and potentially confusing. Finally, considering the fact that the parsed body is an ambiguous domain, forcing an ubiquitous signature is an unnecessary and limiting constraint. However, IF the request method is POST, AND the Content-Type is application/x-www-form-urlencoded, THEN the parsed body MUST be equivalent to $_POST.
1 parent 7848b93 commit 69ea52e

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/ServerRequestInterface.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,32 +136,46 @@ public function getFileParams();
136136
/**
137137
* Retrieve any parameters provided in the request body.
138138
*
139-
* If the request body can be deserialized to an array, this method MAY be
140-
* used to retrieve them.
139+
* If the request Content-Type is application/x-www-form-urlencoded and the
140+
* request method is POST, this method MUST return the contents of $_POST.
141141
*
142-
* @return array The deserialized body parameters, if any.
142+
* Otherwise, this method may return any results of deserializing
143+
* the request body content; as parsing returns structured content, the
144+
* potential types MUST be arrays or objects only. A null value indicates
145+
* the absence of body content.
146+
*
147+
* @return null|array|object The deserialized body parameters, if any.
148+
* These will typically be an array or object.
143149
*/
144-
public function getBodyParams();
150+
public function getParsedBody();
145151

146152
/**
147153
* Create a new instance with the specified body parameters.
148154
*
149-
* These MAY be injected during instantiation from PHP's $_POST
150-
* superglobal. The data IS NOT REQUIRED to come from $_POST, but MUST be
151-
* an array. This method can be used during the request lifetime to inject
152-
* parameters discovered and/or deserialized from the request body; as an
153-
* example, if content negotiation determines that the request data is
154-
* a JSON payload, this method could be used to inject the deserialized
155-
* parameters.
155+
* These MAY be injected during instantiation.
156+
*
157+
* If the request Content-Type is application/x-www-form-urlencoded and the
158+
* request method is POST, use this method ONLY to inject the contents of
159+
* $_POST.
160+
*
161+
* The data IS NOT REQUIRED to come from $_POST, but MUST be the results of
162+
* deserializing the request body content. Deserialization/parsing returns
163+
* structured data, and, as such, this method ONLY accepts arrays or objects,
164+
* or a null value if nothing was available to parse.
165+
*
166+
* As an example, if content negotiation determines that the request data
167+
* is a JSON payload, this method could be used to create a request
168+
* instance with the deserialized parameters.
156169
*
157170
* This method MUST be implemented in such a way as to retain the
158171
* immutability of the message, and MUST return a new instance that has the
159172
* updated body parameters.
160173
*
161-
* @param array $params The deserialized body parameters.
174+
* @param null|array|object $params The deserialized body parameters. These
175+
* will typically be in an array or object.
162176
* @return self
163177
*/
164-
public function withBodyParams(array $params);
178+
public function withParsedBody($params);
165179

166180
/**
167181
* Retrieve attributes derived from the request.

0 commit comments

Comments
 (0)