diff --git a/src/Stream.php b/src/Stream.php index b841fc2a..d6e165e1 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -40,7 +40,10 @@ */ class Stream implements StreamInterface { - use StreamTrait; + /** + * A list of allowed stream resource types that are allowed to instantiate a Stream + */ + private const ALLOWED_STREAM_RESOURCE_TYPES = ['gd', 'stream']; /** * @var resource|null @@ -359,4 +362,17 @@ private function setStream($stream, string $mode = 'r') : void $this->resource = $resource; } + + /** + * Determine if a resource is one of the resource types allowed to instantiate a Stream + * + * @param resource $resource Stream resource. + */ + private function isValidStreamResourceType($resource): bool + { + return ( + is_resource($resource) && + in_array(get_resource_type($resource), self::ALLOWED_STREAM_RESOURCE_TYPES, true) + ); + } } diff --git a/src/StreamFactory.php b/src/StreamFactory.php index ce95a0c8..9f4ab328 100644 --- a/src/StreamFactory.php +++ b/src/StreamFactory.php @@ -21,7 +21,6 @@ class StreamFactory implements StreamFactoryInterface { - use StreamTrait; /** * {@inheritDoc} @@ -48,11 +47,6 @@ public function createStreamFromFile(string $file, string $mode = 'r') : StreamI */ public function createStreamFromResource($resource) : StreamInterface { - if (! $this->isValidStreamResourceType($resource)) { - throw new Exception\InvalidArgumentException( - 'Invalid stream provided; must be a stream resource' - ); - } return new Stream($resource); } } diff --git a/src/StreamTrait.php b/src/StreamTrait.php deleted file mode 100644 index 44f33850..00000000 --- a/src/StreamTrait.php +++ /dev/null @@ -1,30 +0,0 @@ -allowedTypes, true)); - } -}