From b58e9f668ada959619586447e5773ad15258a7ab Mon Sep 17 00:00:00 2001 From: Anton Smirnov Date: Sat, 25 Sep 2021 05:00:09 +0300 Subject: [PATCH 1/3] Future compatible resource check --- composer.json | 3 ++- src/Engine/Decoder.php | 4 +++- src/Engine/Encoder.php | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 358ca59..78b52e7 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ } }, "require": { - "php": "^7.0 | ^8.0" + "php": "^7.0 | ^8.0", + "arokettu/is-resource": "^1.0" }, "require-dev": { "ext-gmp": "*", diff --git a/src/Engine/Decoder.php b/src/Engine/Decoder.php index 95705e6..cd81dfa 100644 --- a/src/Engine/Decoder.php +++ b/src/Engine/Decoder.php @@ -13,6 +13,8 @@ use SandFox\Bencode\Util\IntUtil; use SandFox\Bencode\Util\Util; +use function Arokettu\IsResource\try_get_resource_type; + /** * Class Decoder * @package SandFox\Bencode\Engine @@ -52,7 +54,7 @@ public function __construct($stream, array $options = []) $this->stream = $stream; $this->options = array_merge(self::DEFAULT_OPTIONS, $options); - if (!\is_resource($this->stream) || get_resource_type($this->stream) !== 'stream') { + if (try_get_resource_type($this->stream) !== 'stream') { throw new InvalidArgumentException('Input is not a valid stream'); } } diff --git a/src/Engine/Encoder.php b/src/Engine/Encoder.php index 18b3360..36e44ec 100644 --- a/src/Engine/Encoder.php +++ b/src/Engine/Encoder.php @@ -11,6 +11,8 @@ use SandFox\Bencode\Types\ListType; use SandFox\Bencode\Util\Util; +use function Arokettu\IsResource\try_get_resource_type; + /** * Class Encoder * @package SandFox\Bencode\Engine @@ -39,7 +41,7 @@ public function __construct($data, $stream, array $options) $this->stream = $stream; $this->options = array_merge(self::DEFAULT_OPTIONS, $options); - if (!\is_resource($this->stream) || get_resource_type($this->stream) !== 'stream') { + if (try_get_resource_type($this->stream) !== 'stream') { throw new InvalidArgumentException('Output is not a valid stream'); } } From c7c1e21e479deb03607aefcbe9ffdd3110a82d81 Mon Sep 17 00:00:00 2001 From: Anton Smirnov Date: Sat, 25 Sep 2021 05:01:04 +0300 Subject: [PATCH 2/3] Changelog for 1.7.1 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07d82ea..c97f3f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 1.x +### 1.7.1 + +*Sep 25, 2021* + +* Future compatible stream check + ### 1.7.0 *Sep 17, 2021* From c76b7b26d8ee7705e313a052a7c5980b06075261 Mon Sep 17 00:00:00 2001 From: Anton Smirnov Date: Sat, 25 Sep 2021 05:06:54 +0300 Subject: [PATCH 3/3] Changelog for 2.7.1 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aacd9d8..c6d6a69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 2.x +### 2.7.1 + +*Sep 25, 2021* + +* Future compatible stream check + ### 2.7.0 *Sep 17, 2021*