Skip to content

Commit

Permalink
Add call detach() to getMetadata()
Browse files Browse the repository at this point in the history
  • Loading branch information
devanych authored Nov 15, 2023
1 parent 2500169 commit e3e9dd5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/StreamTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down Expand Up @@ -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 : [];
}

Expand Down

0 comments on commit e3e9dd5

Please sign in to comment.