2626 * @property-read string|NULL $remoteAddress
2727 * @property-read string|NULL $remoteHost
2828 * @property-read string|NULL $rawBody
29+ * @property-read string|NULL $body
2930 */
3031class Request implements IRequest
3132{
@@ -58,9 +59,14 @@ class Request implements IRequest
5859 /** @var callable|NULL */
5960 private $ rawBodyCallback ;
6061
62+ /** @var callable|NULL */
63+ private $ bodyCallback ;
64+
6165
62- public function __construct (UrlScript $ url , $ query = NULL , $ post = NULL , $ files = NULL , $ cookies = NULL ,
63- $ headers = NULL , $ method = NULL , $ remoteAddress = NULL , $ remoteHost = NULL , $ rawBodyCallback = NULL )
66+ public function __construct (
67+ UrlScript $ url , $ query = NULL , $ post = NULL , $ files = NULL , $ cookies = NULL ,
68+ $ headers = NULL , $ method = NULL , $ remoteAddress = NULL , $ remoteHost = NULL ,
69+ $ rawBodyCallback = NULL , $ bodyCallback = NULL )
6470 {
6571 $ this ->url = $ url ;
6672 if ($ query !== NULL ) {
@@ -75,6 +81,7 @@ public function __construct(UrlScript $url, $query = NULL, $post = NULL, $files
7581 $ this ->remoteAddress = $ remoteAddress ;
7682 $ this ->remoteHost = $ remoteHost ;
7783 $ this ->rawBodyCallback = $ rawBodyCallback ;
84+ $ this ->bodyCallback = $ bodyCallback ;
7885 }
7986
8087
@@ -289,7 +296,18 @@ public function getRemoteHost()
289296 */
290297 public function getRawBody ()
291298 {
292- return $ this ->rawBodyCallback ? call_user_func ($ this ->rawBodyCallback ) : NULL ;
299+ return $ this ->rawBodyCallback ? call_user_func ($ this ->rawBodyCallback , $ this ) : NULL ;
300+ }
301+
302+
303+ /**
304+ * Returns parsed content of HTTP request body.
305+ * @return mixed
306+ * @throws InvalidRequestBodyException
307+ */
308+ public function getBody ()
309+ {
310+ return $ this ->bodyCallback ? call_user_func ($ this ->bodyCallback , $ this ) : NULL ;
293311 }
294312
295313
0 commit comments