Commit b58e9f66 authored by Anton Smirnov's avatar Anton Smirnov
Browse files

Future compatible resource check

parent ed5ad64d
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@
        }
    },
    "require": {
        "php": "^7.0 | ^8.0"
        "php": "^7.0 | ^8.0",
        "arokettu/is-resource": "^1.0"
    },
    "require-dev": {
        "ext-gmp": "*",
+3 −1
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ use SandFox\Bencode\Types\BigIntType;
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 @@ final class Decoder
        $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');
        }
    }
+3 −1
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ use SandFox\Bencode\Types\BigIntType;
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 @@ final class Encoder
        $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');
        }
    }