@@ -1515,13 +1515,18 @@ public function createStream(string $content = ''): StreamInterface
1515
1515
1516
1516
public function createStreamFromFile (string $ filename , string $ mode = 'r ' ): StreamInterface
1517
1517
{
1518
- $ resource = @\fopen ($ filename , $ mode );
1518
+ try {
1519
+ $ resource = @\fopen ($ filename , $ mode );
1520
+ } catch (\Throwable $ e ) {
1521
+ throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened. ' , $ filename ));
1522
+ }
1523
+
1519
1524
if (false === $ resource ) {
1520
- if ('' === $ mode || false === \in_array ($ mode [0 ], ['r ' , 'w ' , 'a ' , 'x ' , 'c ' ])) {
1521
- throw new \InvalidArgumentException ('The mode ' . $ mode . ' is invalid. ' );
1525
+ if ('' === $ mode || false === \in_array ($ mode [0 ], ['r ' , 'w ' , 'a ' , 'x ' , 'c ' ], true )) {
1526
+ throw new \InvalidArgumentException (\sprintf ( 'The mode "%s" is invalid. ' , $ mode ) );
1522
1527
}
1523
1528
1524
- throw new \RuntimeException ('The file ' . $ filename . ' cannot be opened. ' );
1529
+ throw new \RuntimeException (\sprintf ( 'The file "%s" cannot be opened. ' , $ filename ) );
1525
1530
}
1526
1531
1527
1532
return Stream::create ($ resource );
@@ -2377,7 +2382,7 @@ public function seek($offset, $whence = \SEEK_SET) /*:void*/
2377
2382
}
2378
2383
2379
2384
if (-1 === \fseek ($ this ->stream , $ offset , $ whence )) {
2380
- throw new \RuntimeException ('Unable to seek to stream position ' . $ offset . ' with whence ' . \var_export ($ whence , true ));
2385
+ throw new \RuntimeException ('Unable to seek to stream position " ' . $ offset . '" with whence ' . \var_export ($ whence , true ));
2381
2386
}
2382
2387
}
2383
2388
@@ -2568,9 +2573,11 @@ public function getStream(): StreamInterface
2568
2573
return $ this ->stream ;
2569
2574
}
2570
2575
2571
- $ resource = \fopen ($ this ->file , 'r ' );
2572
-
2573
- return Stream::create ($ resource );
2576
+ try {
2577
+ return Stream::create (\fopen ($ this ->file , 'r ' ));
2578
+ } catch (\Throwable $ e ) {
2579
+ throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened. ' , $ this ->file ));
2580
+ }
2574
2581
}
2575
2582
2576
2583
public function moveTo ($ targetPath ) /*:void*/
@@ -2589,8 +2596,13 @@ public function moveTo($targetPath) /*:void*/
2589
2596
$ stream ->rewind ();
2590
2597
}
2591
2598
2592
- // Copy the contents of a stream into another stream until end-of-file.
2593
- $ dest = Stream::create (\fopen ($ targetPath , 'w ' ));
2599
+ try {
2600
+ // Copy the contents of a stream into another stream until end-of-file.
2601
+ $ dest = Stream::create (\fopen ($ targetPath , 'w ' ));
2602
+ } catch (\Throwable $ e ) {
2603
+ throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened. ' , $ targetPath ));
2604
+ }
2605
+
2594
2606
while (!$ stream ->eof ()) {
2595
2607
if (!$ dest ->write ($ stream ->read (1048576 ))) {
2596
2608
break ;
@@ -2601,7 +2613,7 @@ public function moveTo($targetPath) /*:void*/
2601
2613
}
2602
2614
2603
2615
if (false === $ this ->moved ) {
2604
- throw new \RuntimeException (\sprintf ('Uploaded file could not be moved to %s ' , $ targetPath ));
2616
+ throw new \RuntimeException (\sprintf ('Uploaded file could not be moved to "%s" ' , $ targetPath ));
2605
2617
}
2606
2618
}
2607
2619
@@ -2676,7 +2688,7 @@ public function __construct(string $uri = '')
2676
2688
{
2677
2689
if ('' !== $ uri ) {
2678
2690
if (false === $ parts = \parse_url ($ uri )) {
2679
- throw new \InvalidArgumentException (" Unable to parse URI: $ uri" );
2691
+ throw new \InvalidArgumentException (\sprintf ( ' Unable to parse URI: "%s" ' , $ uri) );
2680
2692
}
2681
2693
2682
2694
// Apply parse_url parts to a URI.
0 commit comments