Skip to content

Commit

Permalink
Merge pull request #15 from gsteel/support-psr-http-message-2
Browse files Browse the repository at this point in the history
Support psr/http-message:^2
  • Loading branch information
pushkidman authored Jan 15, 2024
2 parents 11d8385 + 8dc91e1 commit dd68118
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
"php-http/discovery": "^1.9",
"php-http/httplug": "^2.1",
"psr/http-client-implementation": "^1.0",
"psr/http-message": "^1.0"
"psr/http-message": "^1.0 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5.15 || ^8.4 || ^9.0",
"php-http/mock-client": "^1.0",
"php-http/message": "^1.0",
"mockery/mockery": "^0.9.4",
"guzzlehttp/psr7": "^1.5.2",
"guzzlehttp/psr7": "^2.6.1",
"http-interop/http-factory-guzzle": "^1.0",
"php-http/guzzle7-adapter": "^0.1",
"friendsofphp/php-cs-fixer": "^2.18",
Expand All @@ -58,5 +58,10 @@
"format": [
"@php vendor/bin/php-cs-fixer fix --verbose --diff"
]
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
}
16 changes: 6 additions & 10 deletions src/Common/HttpLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,12 @@ protected function buildResponse(ResponseInterface $response): array
$contentType = $response->hasHeader('Content-Type') ?
reset($contentTypes) : null;

$body = '';

if ($response->getBody()) {
switch ($contentType) {
case 'application/json':
$body = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
break;
default:
$body = $response->getBody()->getContents();
}
switch ($contentType) {
case 'application/json':
$body = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
break;
default:
$body = $response->getBody()->getContents();
}

return [
Expand Down

0 comments on commit dd68118

Please sign in to comment.