@@ -40,6 +40,7 @@ class ServerRequest implements ServerRequestInterface
4040{
4141 protected ServerRequestInterface $ serverRequest ;
4242
43+ /** @var array<string, callable> */
4344 protected array $ bodyParsers ;
4445
4546 /**
@@ -50,6 +51,9 @@ final public function __construct(ServerRequestInterface $serverRequest)
5051 $ this ->serverRequest = $ serverRequest ;
5152
5253 $ this ->registerMediaTypeParser ('application/json ' , function ($ input ) {
54+ if (!is_string ($ input )) {
55+ return null ;
56+ }
5357 $ result = json_decode ($ input , true );
5458
5559 if (!is_array ($ result )) {
@@ -60,6 +64,9 @@ final public function __construct(ServerRequestInterface $serverRequest)
6064 });
6165
6266 $ xmlParserCallable = function ($ input ) {
67+ if (!is_string ($ input )) {
68+ return null ;
69+ }
6370 $ backup = self ::disableXmlEntityLoader (true );
6471 $ backup_errors = libxml_use_internal_errors (true );
6572 $ result = simplexml_load_string ($ input );
@@ -79,6 +86,9 @@ final public function __construct(ServerRequestInterface $serverRequest)
7986 $ this ->registerMediaTypeParser ('text/xml ' , $ xmlParserCallable );
8087
8188 $ this ->registerMediaTypeParser ('application/x-www-form-urlencoded ' , function ($ input ) {
89+ if (!is_string ($ input )) {
90+ return null ;
91+ }
8292 parse_str ($ input , $ data );
8393 return $ data ;
8494 });
@@ -214,7 +224,7 @@ public function getQueryParams(): array
214224 {
215225 $ queryParams = $ this ->serverRequest ->getQueryParams ();
216226
217- if (is_array ( $ queryParams ) && !empty ($ queryParams )) {
227+ if (!empty ($ queryParams )) {
218228 return $ queryParams ;
219229 }
220230
@@ -650,7 +660,7 @@ public function getServerParam(string $key, $default = null)
650660 public function registerMediaTypeParser (string $ mediaType , callable $ callable ): ServerRequestInterface
651661 {
652662 if ($ callable instanceof Closure) {
653- $ callable = $ callable ->bindTo ($ this );
663+ $ callable = $ callable ->bindTo ($ this ) ?? $ callable ;
654664 }
655665
656666 $ this ->bodyParsers [$ mediaType ] = $ callable ;
0 commit comments