@@ -1515,16 +1515,18 @@ public function createStream(string $content = ''): StreamInterface
1515
1515
1516
1516
public function createStreamFromFile (string $ filename , string $ mode = 'r ' ): StreamInterface
1517
1517
{
1518
- if ('' === $ filename ) {
1519
- throw new \RuntimeException ('Path cannot be empty ' );
1518
+ try {
1519
+ $ resource = @\fopen ($ filename , $ mode );
1520
+ } catch (\Throwable $ e ) {
1521
+ throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened. ' , $ filename ));
1520
1522
}
1521
1523
1522
- if (false === $ resource = @ \fopen ( $ filename , $ mode ) ) {
1524
+ if (false === $ resource ) {
1523
1525
if ('' === $ mode || false === \in_array ($ mode [0 ], ['r ' , 'w ' , 'a ' , 'x ' , 'c ' ], true )) {
1524
1526
throw new \InvalidArgumentException (\sprintf ('The mode "%s" is invalid. ' , $ mode ));
1525
1527
}
1526
1528
1527
- throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened: %s ' , $ filename, \error_get_last ()[ ' message ' ] ?? '' ));
1529
+ throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened. ' , $ filename ));
1528
1530
}
1529
1531
1530
1532
return Stream::create ($ resource );
@@ -2141,9 +2143,6 @@ public function getAttributes(): array
2141
2143
return $ this ->attributes ;
2142
2144
}
2143
2145
2144
- /**
2145
- * @return mixed
2146
- */
2147
2146
public function getAttribute ($ attribute , $ default = null )
2148
2147
{
2149
2148
if (false === \array_key_exists ($ attribute , $ this ->attributes )) {
@@ -2359,20 +2358,16 @@ public function getSize() /*:?int*/
2359
2358
2360
2359
public function tell (): int
2361
2360
{
2362
- if (!isset ($ this ->stream )) {
2363
- throw new \RuntimeException ('Stream is detached ' );
2364
- }
2365
-
2366
- if (false === $ result = @\ftell ($ this ->stream )) {
2367
- throw new \RuntimeException ('Unable to determine stream position: ' . (\error_get_last ()['message ' ] ?? '' ));
2361
+ if (false === $ result = \ftell ($ this ->stream )) {
2362
+ throw new \RuntimeException ('Unable to determine stream position ' );
2368
2363
}
2369
2364
2370
2365
return $ result ;
2371
2366
}
2372
2367
2373
2368
public function eof (): bool
2374
2369
{
2375
- return !isset ( $ this ->stream ) || \feof ($ this ->stream );
2370
+ return !$ this ->stream || \feof ($ this ->stream );
2376
2371
}
2377
2372
2378
2373
public function isSeekable (): bool
@@ -2382,10 +2377,6 @@ public function isSeekable(): bool
2382
2377
2383
2378
public function seek ($ offset , $ whence = \SEEK_SET ) /*:void*/
2384
2379
{
2385
- if (!isset ($ this ->stream )) {
2386
- throw new \RuntimeException ('Stream is detached ' );
2387
- }
2388
-
2389
2380
if (!$ this ->seekable ) {
2390
2381
throw new \RuntimeException ('Stream is not seekable ' );
2391
2382
}
@@ -2407,19 +2398,15 @@ public function isWritable(): bool
2407
2398
2408
2399
public function write ($ string ): int
2409
2400
{
2410
- if (!isset ($ this ->stream )) {
2411
- throw new \RuntimeException ('Stream is detached ' );
2412
- }
2413
-
2414
2401
if (!$ this ->writable ) {
2415
2402
throw new \RuntimeException ('Cannot write to a non-writable stream ' );
2416
2403
}
2417
2404
2418
2405
// We can't know the size after writing anything
2419
2406
$ this ->size = null ;
2420
2407
2421
- if (false === $ result = @ \fwrite ($ this ->stream , $ string )) {
2422
- throw new \RuntimeException ('Unable to write to stream: ' . ( \error_get_last ()[ ' message ' ] ?? '' ) );
2408
+ if (false === $ result = \fwrite ($ this ->stream , $ string )) {
2409
+ throw new \RuntimeException ('Unable to write to stream ' );
2423
2410
}
2424
2411
2425
2412
return $ result ;
@@ -2432,16 +2419,12 @@ public function isReadable(): bool
2432
2419
2433
2420
public function read ($ length ): string
2434
2421
{
2435
- if (!isset ($ this ->stream )) {
2436
- throw new \RuntimeException ('Stream is detached ' );
2437
- }
2438
-
2439
2422
if (!$ this ->readable ) {
2440
2423
throw new \RuntimeException ('Cannot read from non-readable stream ' );
2441
2424
}
2442
2425
2443
- if (false === $ result = @ \fread ($ this ->stream , $ length )) {
2444
- throw new \RuntimeException ('Unable to read from stream: ' . ( \error_get_last ()[ ' message ' ] ?? '' ) );
2426
+ if (false === $ result = \fread ($ this ->stream , $ length )) {
2427
+ throw new \RuntimeException ('Unable to read from stream ' );
2445
2428
}
2446
2429
2447
2430
return $ result ;
@@ -2450,19 +2433,16 @@ public function read($length): string
2450
2433
public function getContents (): string
2451
2434
{
2452
2435
if (!isset ($ this ->stream )) {
2453
- throw new \RuntimeException ('Stream is detached ' );
2436
+ throw new \RuntimeException ('Unable to read stream contents ' );
2454
2437
}
2455
2438
2456
- if (false === $ contents = @ \stream_get_contents ($ this ->stream )) {
2457
- throw new \RuntimeException ('Unable to read stream contents: ' . ( \error_get_last ()[ ' message ' ] ?? '' ) );
2439
+ if (false === $ contents = \stream_get_contents ($ this ->stream )) {
2440
+ throw new \RuntimeException ('Unable to read stream contents ' );
2458
2441
}
2459
2442
2460
2443
return $ contents ;
2461
2444
}
2462
2445
2463
- /**
2464
- * @return mixed
2465
- */
2466
2446
public function getMetadata ($ key = null )
2467
2447
{
2468
2448
if (!isset ($ this ->stream )) {
@@ -2559,7 +2539,7 @@ public function __construct($streamOrFile, $size, $errorStatus, $clientFilename
2559
2539
2560
2540
if (\UPLOAD_ERR_OK === $ this ->error ) {
2561
2541
// Depending on the value set file or stream variable.
2562
- if (\is_string ($ streamOrFile ) && '' !== $ streamOrFile ) {
2542
+ if (\is_string ($ streamOrFile )) {
2563
2543
$ this ->file = $ streamOrFile ;
2564
2544
} elseif (\is_resource ($ streamOrFile )) {
2565
2545
$ this ->stream = Stream::create ($ streamOrFile );
@@ -2593,11 +2573,11 @@ public function getStream(): StreamInterface
2593
2573
return $ this ->stream ;
2594
2574
}
2595
2575
2596
- if (false === $ resource = @\fopen ($ this ->file , 'r ' )) {
2597
- throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened: %s ' , $ this ->file , \error_get_last ()['message ' ] ?? '' ));
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 ));
2598
2580
}
2599
-
2600
- return Stream::create ($ resource );
2601
2581
}
2602
2582
2603
2583
public function moveTo ($ targetPath ) /*:void*/
@@ -2609,23 +2589,20 @@ public function moveTo($targetPath) /*:void*/
2609
2589
}
2610
2590
2611
2591
if (null !== $ this ->file ) {
2612
- $ this ->moved = 'cli ' === \PHP_SAPI ? @\rename ($ this ->file , $ targetPath ) : @\move_uploaded_file ($ this ->file , $ targetPath );
2613
-
2614
- if (false === $ this ->moved ) {
2615
- throw new \RuntimeException (\sprintf ('Uploaded file could not be moved to "%s": %s ' , $ targetPath , \error_get_last ()['message ' ] ?? '' ));
2616
- }
2592
+ $ this ->moved = 'cli ' === \PHP_SAPI ? \rename ($ this ->file , $ targetPath ) : \move_uploaded_file ($ this ->file , $ targetPath );
2617
2593
} else {
2618
2594
$ stream = $ this ->getStream ();
2619
2595
if ($ stream ->isSeekable ()) {
2620
2596
$ stream ->rewind ();
2621
2597
}
2622
2598
2623
- if (false === $ resource = @\fopen ($ targetPath , 'w ' )) {
2624
- throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened: %s ' , $ targetPath , \error_get_last ()['message ' ] ?? '' ));
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 ));
2625
2604
}
2626
2605
2627
- $ dest = Stream::create ($ resource );
2628
-
2629
2606
while (!$ stream ->eof ()) {
2630
2607
if (!$ dest ->write ($ stream ->read (1048576 ))) {
2631
2608
break ;
@@ -2634,6 +2611,10 @@ public function moveTo($targetPath) /*:void*/
2634
2611
2635
2612
$ this ->moved = true ;
2636
2613
}
2614
+
2615
+ if (false === $ this ->moved ) {
2616
+ throw new \RuntimeException (\sprintf ('Uploaded file could not be moved to "%s" ' , $ targetPath ));
2617
+ }
2637
2618
}
2638
2619
2639
2620
public function getSize (): int
@@ -9893,6 +9874,7 @@ class OpenApiBuilder
9893
9874
private $ openapi ;
9894
9875
private $ records ;
9895
9876
private $ columns ;
9877
+ private $ status ;
9896
9878
private $ builders ;
9897
9879
9898
9880
public function __construct (ReflectionService $ reflection , array $ base , array $ controllers , array $ builders )
0 commit comments