From 89c38c31e611897da3a71b19bd5a61903609127d Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Tue, 20 Jul 2021 07:19:32 -0500 Subject: [PATCH] Switch to future-compatible Guzzle --- composer.json | 2 +- src/StreamFactory.php | 21 +-------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index af72708..863ffbd 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/StreamFactory.php b/src/StreamFactory.php index d989854..6fe772e 100644 --- a/src/StreamFactory.php +++ b/src/StreamFactory.php @@ -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); } }