88 * @license MIT
99 */
1010
11+ declare (strict_types=1 );
12+
1113namespace chillerlan \HTTP \Utils ;
1214
13- use Psr \Http \Message \{MessageInterface , RequestInterface , ResponseInterface };
15+ use Psr \Http \Message \{MessageInterface , RequestInterface , ResponseInterface , ServerRequestInterface };
1416use RuntimeException , Throwable ;
1517use function call_user_func , extension_loaded , function_exists , gzdecode , gzinflate , gzuncompress , implode ,
1618 in_array , json_decode , json_encode , simplexml_load_string , sprintf , strtolower , trim ;
@@ -39,14 +41,14 @@ public static function getContents(MessageInterface $message):string{
3941 /**
4042 * @throws \JsonException
4143 */
42- public static function decodeJSON (MessageInterface $ message , bool $ assoc = null ):mixed {
44+ public static function decodeJSON (MessageInterface $ message , bool | null $ assoc = null ):mixed {
4345 return json_decode (self ::getContents ($ message ), ($ assoc ?? false ), 512 , JSON_THROW_ON_ERROR );
4446 }
4547
4648 /**
4749 * @return \SimpleXMLElement|\stdClass|mixed
4850 */
49- public static function decodeXML (MessageInterface $ message , bool $ assoc = null ):mixed {
51+ public static function decodeXML (MessageInterface $ message , bool | null $ assoc = null ):mixed {
5052 $ data = simplexml_load_string (self ::getContents ($ message ));
5153
5254 return $ assoc === true
@@ -57,7 +59,7 @@ public static function decodeXML(MessageInterface $message, bool $assoc = null):
5759 /**
5860 * Returns the string representation of an HTTP message. (from Guzzle)
5961 */
60- public static function toString (MessageInterface $ message , bool $ appendBody = null ):string {
62+ public static function toString (MessageInterface $ message , bool | null $ appendBody = null ):string {
6163 $ appendBody ??= true ;
6264 $ msg = '' ;
6365
@@ -144,7 +146,9 @@ protected static function call_decompress_func(string $func, string $data):strin
144146 /**
145147 * Sets a Content-Length header in the given message in case it does not exist and body size is not null
146148 */
147- public static function setContentLengthHeader (MessageInterface $ message ):MessageInterface {
149+ public static function setContentLengthHeader (
150+ MessageInterface $ message
151+ ):MessageInterface |RequestInterface |ResponseInterface |ServerRequestInterface {
148152 $ bodySize = $ message ->getBody ()->getSize ();
149153
150154 if (!$ message ->hasHeader ('Content-Length ' ) && $ bodySize !== null && $ bodySize > 0 ){
@@ -162,9 +166,9 @@ public static function setContentLengthHeader(MessageInterface $message):Message
162166 */
163167 public static function setContentTypeHeader (
164168 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 {
168172 $ mime = (
169173 MimeTypeUtil::getFromExtension (trim (($ extension ?? '' ), ". \t\n\r\0\x0B" ))
170174 ?? MimeTypeUtil::getFromFilename (($ filename ?? '' ))
0 commit comments