@@ -268,14 +268,17 @@ public function getParsedBody()
268
268
return null ;
269
269
}
270
270
271
- // Look for a media type with a structured syntax suffix (RFC 6839)
272
- $ parts = explode ('+ ' , $ mediaType );
273
- if (count ($ parts ) >= 2 ) {
274
- $ mediaType = 'application/ ' . $ parts [count ($ parts )-1 ];
271
+ // Check if this specific media type has a parser registered first
272
+ if (!isset ($ this ->bodyParsers [$ mediaType ])) {
273
+ // If not, look for a media type with a structured syntax suffix (RFC 6839)
274
+ $ parts = explode ('+ ' , $ mediaType );
275
+ if (count ($ parts ) >= 2 ) {
276
+ $ mediaType = 'application/ ' . $ parts [count ($ parts ) - 1 ];
277
+ }
275
278
}
276
279
277
- if (isset ($ this ->bodyParsers [$ mediaType ]) === true ) {
278
- $ body = (string ) $ this ->getBody ();
280
+ if (isset ($ this ->bodyParsers [$ mediaType ])) {
281
+ $ body = (string )$ this ->getBody ();
279
282
$ parsed = $ this ->bodyParsers [$ mediaType ]($ body );
280
283
281
284
if (!is_null ($ parsed ) && !is_object ($ parsed ) && !is_array ($ parsed )) {
@@ -762,7 +765,7 @@ public function withUri(UriInterface $uri, $preserveHost = false)
762
765
*
763
766
* @return string|null
764
767
*/
765
- public function getContentCharset ()
768
+ public function getContentCharset (): ? string
766
769
{
767
770
$ mediaTypeParams = $ this ->getMediaTypeParams ();
768
771
@@ -780,7 +783,7 @@ public function getContentCharset()
780
783
*
781
784
* @return string|null The serverRequest content type, if known
782
785
*/
783
- public function getContentType ()
786
+ public function getContentType (): ? string
784
787
{
785
788
$ result = $ this ->serverRequest ->getHeader ('Content-Type ' );
786
789
return $ result ? $ result [0 ] : null ;
@@ -793,7 +796,7 @@ public function getContentType()
793
796
*
794
797
* @return int|null
795
798
*/
796
- public function getContentLength ()
799
+ public function getContentLength (): ? int
797
800
{
798
801
$ result = $ this ->serverRequest ->getHeader ('Content-Length ' );
799
802
return $ result ? (int ) $ result [0 ] : null ;
@@ -828,7 +831,7 @@ public function getCookieParam($key, $default = null)
828
831
*
829
832
* @return string|null The serverRequest media type, minus content-type params
830
833
*/
831
- public function getMediaType ()
834
+ public function getMediaType (): ? string
832
835
{
833
836
$ contentType = $ this ->getContentType ();
834
837
@@ -848,9 +851,9 @@ public function getMediaType()
848
851
*
849
852
* Note: This method is not part of the PSR-7 standard.
850
853
*
851
- * @return array
854
+ * @return mixed[]
852
855
*/
853
- public function getMediaTypeParams ()
856
+ public function getMediaTypeParams (): array
854
857
{
855
858
$ contentType = $ this ->getContentType ();
856
859
$ contentTypeParams = [];
@@ -901,9 +904,9 @@ public function getParam($key, $default = null)
901
904
*
902
905
* Note: This method is not part of the PSR-7 standard.
903
906
*
904
- * @return array
907
+ * @return mixed[]
905
908
*/
906
- public function getParams ()
909
+ public function getParams (): array
907
910
{
908
911
$ params = $ this ->getQueryParams ();
909
912
$ postParams = $ this ->getParsedBody ();
@@ -1003,7 +1006,7 @@ public function registerMediaTypeParser($mediaType, callable $callable): ServerR
1003
1006
*
1004
1007
* @return bool
1005
1008
*/
1006
- public function isDelete ()
1009
+ public function isDelete (): bool
1007
1010
{
1008
1011
return $ this ->isMethod ('DELETE ' );
1009
1012
}
@@ -1015,7 +1018,7 @@ public function isDelete()
1015
1018
*
1016
1019
* @return bool
1017
1020
*/
1018
- public function isGet ()
1021
+ public function isGet (): bool
1019
1022
{
1020
1023
return $ this ->isMethod ('GET ' );
1021
1024
}
@@ -1027,7 +1030,7 @@ public function isGet()
1027
1030
*
1028
1031
* @return bool
1029
1032
*/
1030
- public function isHead ()
1033
+ public function isHead (): bool
1031
1034
{
1032
1035
return $ this ->isMethod ('HEAD ' );
1033
1036
}
@@ -1040,7 +1043,7 @@ public function isHead()
1040
1043
* @param string $method HTTP method
1041
1044
* @return bool
1042
1045
*/
1043
- public function isMethod ($ method )
1046
+ public function isMethod ($ method ): bool
1044
1047
{
1045
1048
return $ this ->serverRequest ->getMethod () === $ method ;
1046
1049
}
@@ -1052,7 +1055,7 @@ public function isMethod($method)
1052
1055
*
1053
1056
* @return bool
1054
1057
*/
1055
- public function isOptions ()
1058
+ public function isOptions (): bool
1056
1059
{
1057
1060
return $ this ->isMethod ('OPTIONS ' );
1058
1061
}
@@ -1064,7 +1067,7 @@ public function isOptions()
1064
1067
*
1065
1068
* @return bool
1066
1069
*/
1067
- public function isPatch ()
1070
+ public function isPatch (): bool
1068
1071
{
1069
1072
return $ this ->isMethod ('PATCH ' );
1070
1073
}
@@ -1076,7 +1079,7 @@ public function isPatch()
1076
1079
*
1077
1080
* @return bool
1078
1081
*/
1079
- public function isPost ()
1082
+ public function isPost (): bool
1080
1083
{
1081
1084
return $ this ->isMethod ('POST ' );
1082
1085
}
@@ -1088,7 +1091,7 @@ public function isPost()
1088
1091
*
1089
1092
* @return bool
1090
1093
*/
1091
- public function isPut ()
1094
+ public function isPut (): bool
1092
1095
{
1093
1096
return $ this ->isMethod ('PUT ' );
1094
1097
}
@@ -1100,7 +1103,7 @@ public function isPut()
1100
1103
*
1101
1104
* @return bool
1102
1105
*/
1103
- public function isXhr ()
1106
+ public function isXhr (): bool
1104
1107
{
1105
1108
return $ this ->serverRequest ->getHeaderLine ('X-Requested-With ' ) === 'XMLHttpRequest ' ;
1106
1109
}
0 commit comments