File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ public function __construct(mixed $stream = null, string $permission = "r+")
5757 } else {
5858 $ this ->stream = $ stream ;
5959 $ this ->permission = $ permission ;
60- $ this ->resource = fopen ($ this ->stream , $ this ->permission );
60+ $ this ->resource = $ this -> fopen ($ this ->stream , $ this ->permission );
6161 $ this ->meta = $ this ->getMetadata ();
6262 }
6363 }
@@ -297,7 +297,26 @@ public function withContext(array $opts): StreamInterface
297297 {
298298 $ inst = clone $ this ;
299299 $ context = stream_context_create ($ opts );
300- $ inst ->resource = fopen ($ this ->stream , $ this ->permission , false , $ context );
300+ $ inst ->resource = $ this -> fopen ($ this ->stream , $ this ->permission , false , $ context );
301301 return $ inst ;
302302 }
303+
304+ /**
305+ * Open a resource correct with the right resource
306+ * @param ...$fArgs
307+ * @return false|resource
308+ * @throws \RuntimeException on error.
309+ */
310+ private function fopen (...$ fArgs )
311+ {
312+ set_error_handler (function ($ errorNo , $ errorStr ) {
313+ throw new RuntimeException ('Failed to open stream: ' . $ errorStr , $ errorNo );
314+ });
315+ try {
316+ $ this ->resource = fopen (...$ fArgs );
317+ } finally {
318+ restore_error_handler ();
319+ }
320+ return $ this ->resource ;
321+ }
303322}
You can’t perform that action at this time.
0 commit comments