Skip to content

Commit af74f4b

Browse files
committed
:octocat: thanks, i hate it.
1 parent 092eb35 commit af74f4b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Psr7/message_helpers.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,9 @@ function normalize_nested_file_spec(array $files = []):array{
390390
* @return \stdClass|array|bool
391391
*/
392392
function get_json(ResponseInterface $response, bool $assoc = null){
393-
$body = $response->getBody();
394-
$data = \json_decode($body->getContents(), $assoc);
393+
$data = \json_decode($response->getBody()->__toString(), $assoc);
395394

396-
$body->rewind();
395+
$response->getBody()->rewind();
397396

398397
return $data;
399398
}
@@ -405,10 +404,9 @@ function get_json(ResponseInterface $response, bool $assoc = null){
405404
* @return \SimpleXMLElement|array|bool
406405
*/
407406
function get_xml(ResponseInterface $response, bool $assoc = null){
408-
$body = $response->getBody();
409-
$data = \simplexml_load_string($body->getContents());
407+
$data = \simplexml_load_string($response->getBody()->__toString());
410408

411-
$body->rewind();
409+
$response->getBody()->rewind();
412410

413411
return $assoc === true
414412
? \json_decode(\json_encode($data), true) // cruel
@@ -441,7 +439,10 @@ function message_to_string(MessageInterface $message):string{
441439
$msg .= "\r\n".$name.': '.\implode(', ', $values);
442440
}
443441

444-
return $msg."\r\n\r\n".$message->getBody();
442+
$data = $message->getBody()->__toString();
443+
$message->getBody()->rewind();
444+
445+
return $msg."\r\n\r\n".$data;
445446
}
446447

447448
/**
@@ -452,7 +453,8 @@ function message_to_string(MessageInterface $message):string{
452453
* @return string
453454
*/
454455
function decompress_content(MessageInterface $message):string{
455-
$data = $message->getBody()->getContents();
456+
$data = $message->getBody()->__toString();
457+
$message->getBody()->rewind();
456458

457459
switch($message->getHeaderLine('content-encoding')){
458460
# case 'br' : return \brotli_uncompress($data); // @todo: https://github.com/kjdev/php-ext-brotli

0 commit comments

Comments
 (0)