8
8
* @license MIT
9
9
*/
10
10
11
+ declare (strict_types=1 );
12
+
11
13
namespace chillerlan \HTTP \Utils ;
12
14
13
- use Psr \Http \Message \{MessageInterface , RequestInterface , ResponseInterface };
15
+ use Psr \Http \Message \{MessageInterface , RequestInterface , ResponseInterface , ServerRequestInterface };
14
16
use RuntimeException , Throwable ;
15
17
use function call_user_func , extension_loaded , function_exists , gzdecode , gzinflate , gzuncompress , implode ,
16
18
in_array , json_decode , json_encode , simplexml_load_string , sprintf , strtolower , trim ;
@@ -39,14 +41,14 @@ public static function getContents(MessageInterface $message):string{
39
41
/**
40
42
* @throws \JsonException
41
43
*/
42
- public static function decodeJSON (MessageInterface $ message , bool $ assoc = null ):mixed {
44
+ public static function decodeJSON (MessageInterface $ message , bool | null $ assoc = null ):mixed {
43
45
return json_decode (self ::getContents ($ message ), ($ assoc ?? false ), 512 , JSON_THROW_ON_ERROR );
44
46
}
45
47
46
48
/**
47
49
* @return \SimpleXMLElement|\stdClass|mixed
48
50
*/
49
- public static function decodeXML (MessageInterface $ message , bool $ assoc = null ):mixed {
51
+ public static function decodeXML (MessageInterface $ message , bool | null $ assoc = null ):mixed {
50
52
$ data = simplexml_load_string (self ::getContents ($ message ));
51
53
52
54
return $ assoc === true
@@ -57,7 +59,7 @@ public static function decodeXML(MessageInterface $message, bool $assoc = null):
57
59
/**
58
60
* Returns the string representation of an HTTP message. (from Guzzle)
59
61
*/
60
- public static function toString (MessageInterface $ message , bool $ appendBody = null ):string {
62
+ public static function toString (MessageInterface $ message , bool | null $ appendBody = null ):string {
61
63
$ appendBody ??= true ;
62
64
$ msg = '' ;
63
65
@@ -144,7 +146,9 @@ protected static function call_decompress_func(string $func, string $data):strin
144
146
/**
145
147
* Sets a Content-Length header in the given message in case it does not exist and body size is not null
146
148
*/
147
- public static function setContentLengthHeader (MessageInterface $ message ):MessageInterface {
149
+ public static function setContentLengthHeader (
150
+ MessageInterface $ message
151
+ ):MessageInterface |RequestInterface |ResponseInterface |ServerRequestInterface {
148
152
$ bodySize = $ message ->getBody ()->getSize ();
149
153
150
154
if (!$ message ->hasHeader ('Content-Length ' ) && $ bodySize !== null && $ bodySize > 0 ){
@@ -162,9 +166,9 @@ public static function setContentLengthHeader(MessageInterface $message):Message
162
166
*/
163
167
public static function setContentTypeHeader (
164
168
MessageInterface $ message ,
165
- string $ filename = null ,
166
- string $ extension = null
167
- ):MessageInterface {
169
+ string | null $ filename = null ,
170
+ string | null $ extension = null ,
171
+ ):MessageInterface | RequestInterface | ResponseInterface | ServerRequestInterface {
168
172
$ mime = (
169
173
MimeTypeUtil::getFromExtension (trim (($ extension ?? '' ), ". \t\n\r\0\x0B" ))
170
174
?? MimeTypeUtil::getFromFilename (($ filename ?? '' ))
0 commit comments