From e3e9dd563c63608752d3f52193c8e8fe2c6b482b Mon Sep 17 00:00:00 2001 From: Evgeniy Zyubin Date: Wed, 15 Nov 2023 14:27:31 +0300 Subject: [PATCH] Add call detach() to getMetadata() --- src/StreamTrait.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/StreamTrait.php b/src/StreamTrait.php index d2b291f..80ba474 100644 --- a/src/StreamTrait.php +++ b/src/StreamTrait.php @@ -325,6 +325,10 @@ public function read($length): string */ public function getContents(): string { + if (!$this->resource) { + throw new RuntimeException('No resource available. Cannot read.'); + } + if (!$this->isReadable()) { throw new RuntimeException('Stream is not readable.'); } @@ -361,6 +365,7 @@ public function getMetadata($key = null) try { $metadata = stream_get_meta_data($this->resource); } catch (Throwable $e) { + $this->detach(); return $key ? null : []; }