@@ -199,13 +199,13 @@ class Request
199
199
/**
200
200
* Constructor.
201
201
*
202
- * @param array $query The GET parameters
203
- * @param array $request The POST parameters
204
- * @param array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
205
- * @param array $cookies The COOKIE parameters
206
- * @param array $files The FILES parameters
207
- * @param array $server The SERVER parameters
208
- * @param string $content The raw body data
202
+ * @param array $query The GET parameters
203
+ * @param array $request The POST parameters
204
+ * @param array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
205
+ * @param array $cookies The COOKIE parameters
206
+ * @param array $files The FILES parameters
207
+ * @param array $server The SERVER parameters
208
+ * @param string|resource $content The raw body data
209
209
*
210
210
* @api
211
211
*/
@@ -219,13 +219,13 @@ public function __construct(array $query = array(), array $request = array(), ar
219
219
*
220
220
* This method also re-initializes all properties.
221
221
*
222
- * @param array $query The GET parameters
223
- * @param array $request The POST parameters
224
- * @param array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
225
- * @param array $cookies The COOKIE parameters
226
- * @param array $files The FILES parameters
227
- * @param array $server The SERVER parameters
228
- * @param string $content The raw body data
222
+ * @param array $query The GET parameters
223
+ * @param array $request The POST parameters
224
+ * @param array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
225
+ * @param array $cookies The COOKIE parameters
226
+ * @param array $files The FILES parameters
227
+ * @param array $server The SERVER parameters
228
+ * @param string|resource $content The raw body data
229
229
*
230
230
* @api
231
231
*/
@@ -1465,16 +1465,38 @@ public function isMethodSafe()
1465
1465
*/
1466
1466
public function getContent ($ asResource = false )
1467
1467
{
1468
- if (PHP_VERSION_ID < 50600 && (false === $ this ->content || (true === $ asResource && null !== $ this ->content ))) {
1468
+ $ currentContentIsResource = is_resource ($ this ->content );
1469
+ if (PHP_VERSION_ID < 50600 && false === $ this ->content ) {
1469
1470
throw new \LogicException ('getContent() can only be called once when using the resource return type and PHP below 5.6. ' );
1470
1471
}
1471
1472
1472
1473
if (true === $ asResource ) {
1474
+ if ($ currentContentIsResource ) {
1475
+ rewind ($ this ->content );
1476
+
1477
+ return $ this ->content ;
1478
+ }
1479
+
1480
+ // Content passed in parameter (test)
1481
+ if (is_string ($ this ->content )) {
1482
+ $ resource = fopen ('php://temp ' ,'r+ ' );
1483
+ fwrite ($ resource , $ this ->content );
1484
+ rewind ($ resource );
1485
+
1486
+ return $ resource ;
1487
+ }
1488
+
1473
1489
$ this ->content = false ;
1474
1490
1475
1491
return fopen ('php://input ' , 'rb ' );
1476
1492
}
1477
1493
1494
+ if ($ currentContentIsResource ) {
1495
+ rewind ($ this ->content );
1496
+
1497
+ return stream_get_contents ($ this ->content );
1498
+ }
1499
+
1478
1500
if (null === $ this ->content ) {
1479
1501
$ this ->content = file_get_contents ('php://input ' );
1480
1502
}
0 commit comments