Skip to content

Commit

Permalink
Switch to future-compatible Guzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowhand committed Jul 20, 2021
1 parent 062421d commit 89c38c3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require": {
"php": ">=7.3",
"psr/http-factory": "^1.0",
"guzzlehttp/psr7": "^1.4.2||^2.0"
"guzzlehttp/psr7": "^1.7||^2.0"
},
"require-dev": {
"http-interop/http-factory-tests": "^0.9",
Expand Down
21 changes: 1 addition & 20 deletions src/StreamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,20 @@
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;

use function GuzzleHttp\Psr7\stream_for;
use function GuzzleHttp\Psr7\try_fopen;

class StreamFactory implements StreamFactoryInterface
{
public function createStream(string $content = ''): StreamInterface
{
if (\function_exists('stream_for')) {
// fallback for guzzlehttp/psr7<1.7.0
return stream_for($content);
}
return Utils::streamFor($content);
}

public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface
{
if (\function_exists('try_fopen') && \function_exists('steam_for')) {
// fallback for guzzlehttp/psr7<1.7.0
$resource = try_fopen($file, $mode);

return stream_for($resource);
}
$resource = Utils::tryFopen($file, $mode);

return new Stream($resource);
return $this->createStreamFromResource(Utils::tryFopen($file, $mode));
}

public function createStreamFromResource($resource): StreamInterface
{
if (\function_exists('stream_for')) {
// fallback for guzzlehttp/psr7<1.7.0
return stream_for($resource);
}
return new Stream($resource);
}
}

0 comments on commit 89c38c3

Please sign in to comment.