PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.20
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.20
1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
woocommerce-pos / vendor_prefixed / guzzlehttp / psr7 / src / StreamTimeout.php

StreamTimeout.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.20, at vendor_prefixed/guzzlehttp/psr7/src/StreamTimeout.php

89 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WCPOS\Vendor\GuzzleHttp\Psr7;
5
6 use WCPOS\Vendor\GuzzleHttp\Psr7\Exception\TimeoutException;
7 use WCPOS\Vendor\Psr\Http\Message\StreamInterface;
8 /**
9 * @internal
10 */
11 final class StreamTimeout
12 {
13 private function __construct()
14 {
15 }
16 public static function read(StreamInterface $stream, int $length, string $timeoutMessage) : string
17 {
18 try {
19 $buffer = $stream->read($length);
20 } catch (TimeoutException $e) {
21 throw $e;
22 } catch (\RuntimeException $e) {
23 self::throwIfReadTimedOut($stream, $timeoutMessage, $e);
24 throw $e;
25 }
26 if ($buffer === '') {
27 self::throwIfReadTimedOut($stream, $timeoutMessage);
28 }
29 return $buffer;
30 }
31 public static function throwIfReadTimedOut(StreamInterface $stream, string $message, ?\Throwable $previous = null) : void
32 {
33 if (self::isReadTimedOut($stream)) {
34 throw new TimeoutException($message, 0, $previous);
35 }
36 }
37 public static function throwIfWriteTimedOut(StreamInterface $stream, ?\Throwable $previous = null) : void
38 {
39 if (self::isWriteTimedOut($stream)) {
40 throw new TimeoutException('Unable to write to stream: timed out', 0, $previous);
41 }
42 }
43 public static function isReadTimedOut(StreamInterface $stream) : bool
44 {
45 try {
46 if ($stream->getMetadata('timed_out') !== \true) {
47 return \false;
48 }
49 return !$stream->eof();
50 } catch (\Throwable $e) {
51 return \false;
52 }
53 }
54 public static function isWriteTimedOut(StreamInterface $stream) : bool
55 {
56 try {
57 return $stream->getMetadata('timed_out') === \true;
58 } catch (\Throwable $e) {
59 return \false;
60 }
61 }
62 /**
63 * @param resource $resource
64 */
65 public static function isResourceReadTimedOut($resource) : bool
66 {
67 try {
68 /** @var array<string, mixed> $metadata */
69 $metadata = \stream_get_meta_data($resource);
70 return ($metadata['timed_out'] ?? \false) === \true && !\feof($resource);
71 } catch (\Throwable $e) {
72 return \false;
73 }
74 }
75 /**
76 * @param resource $resource
77 */
78 public static function isResourceWriteTimedOut($resource) : bool
79 {
80 try {
81 /** @var array<string, mixed> $metadata */
82 $metadata = \stream_get_meta_data($resource);
83 return ($metadata['timed_out'] ?? \false) === \true;
84 } catch (\Throwable $e) {
85 return \false;
86 }
87 }
88 }
89