Skip to content

Commit

Permalink
Handling guzzlehttp/psr7: ^1.7 || ^2.0 see issue #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Whitlock committed Jan 27, 2022
1 parent ec60a85 commit 8483cf3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"php": "^7.1.3|^8.0",
"ext-zip" : "*",
"ext-json": "*",
"guzzlehttp/guzzle-services": "^1.1",
"guzzlehttp/guzzle-services": "~1.3.1",
"guzzlehttp/psr7": "~2.1.0",
"symfony/console": "~4.0|~5.0"
},
"require-dev" : {
Expand Down
14 changes: 10 additions & 4 deletions src/Http/Request/BodyLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use GuzzleHttp\Command\Guzzle\RequestLocation\AbstractLocation;
use GuzzleHttp\Command\CommandInterface;
use GuzzleHttp\Command\Guzzle\Parameter;
use GuzzleHttp\Psr7;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\RequestInterface;

Expand Down Expand Up @@ -47,8 +46,15 @@ public function visit(
$value = $command[$param->getName()];
$request = $request->withHeader('Content-Type', 'application/octet-stream');

// TODO Replace deprecated function with Psr7\Utils::streamFor
// https://github.com/loco/loco-php-sdk/issues/12
return $request->withBody(Psr7\stream_for($value));
// guzzle-services composer.json has guzzlehttp/psr7: ^1.7 || ^2.0
// https://github.com/loco/loco-php-sdk/issues/12
$createBody = ['\\GuzzleHttp\\Psr7\\Utils','streamFor'];
if (! is_callable($createBody)) {
$createBody = '\\GuzzleHttp\\Psr7\\stream_for';
if (! function_exists($createBody)) {
throw new \RuntimeException('Unknown \\GuzzleHttp\\Psr7 version');
}
}
return $request->withBody(call_user_func($createBody, $value));
}
}

0 comments on commit 8483cf3

Please sign in to comment.