diff --git a/CHANGELOG.md b/CHANGELOG.md index 02ce3ca..6a9baa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,12 @@ ## 2.x +### 2.7.1 + +*Sep 25, 2021* + +* Future compatible stream check + ### 2.7.0 *Sep 17, 2021* @@ -98,6 +104,12 @@ ## 1.x +### 1.7.1 + +*Sep 25, 2021* + +* Future compatible stream check + ### 1.7.0 *Sep 17, 2021* diff --git a/composer.json b/composer.json index a9c0bb4..c2f91fd 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ } }, "require": { - "php": "^8.1" + "php": "^8.1", + "arokettu/is-resource": "^1.0" }, "require-dev": { "ext-gmp": "*", diff --git a/src/Engine/Decoder.php b/src/Engine/Decoder.php index b8c52a4..8a8e1cf 100644 --- a/src/Engine/Decoder.php +++ b/src/Engine/Decoder.php @@ -8,6 +8,8 @@ use SandFox\Bencode\Exceptions\ParseErrorException; use SandFox\Bencode\Util\IntUtil; +use function Arokettu\IsResource\try_get_resource_type; + /** * @internal */ @@ -36,7 +38,7 @@ public function __construct( private \Closure $dictHandler, private \Closure $bigIntHandler, ) { - if (!\is_resource($this->stream) || get_resource_type($this->stream) !== 'stream') { + if (try_get_resource_type($stream) !== 'stream') { throw new InvalidArgumentException('Input is not a valid stream'); } } diff --git a/src/Engine/Encoder.php b/src/Engine/Encoder.php index 6f66138..d9ed516 100644 --- a/src/Engine/Encoder.php +++ b/src/Engine/Encoder.php @@ -11,6 +11,8 @@ use SandFox\Bencode\Types\DictType; use SandFox\Bencode\Types\ListType; +use function Arokettu\IsResource\try_get_resource_type; + /** * @internal */ @@ -28,7 +30,7 @@ public function __construct( private bool $useJsonSerializable, private bool $useStringable, ) { - 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'); } }