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 / StreamWrapper.php

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

185 lines 5.0 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\Psr\Http\Message\StreamInterface;
7 /**
8 * Converts Guzzle streams into PHP stream resources.
9 *
10 * @see https://www.php.net/streamwrapper
11 */
12 final class StreamWrapper
13 {
14 /** @var resource */
15 public $context;
16 private StreamInterface $stream;
17 /** @var string r, r+, or w */
18 private string $mode;
19 /**
20 * Returns a resource representing the stream.
21 *
22 * @param StreamInterface $stream The stream to get a resource for
23 *
24 * @return resource
25 *
26 * @throws \InvalidArgumentException if stream is not readable or writable
27 */
28 public static function getResource(StreamInterface $stream)
29 {
30 self::register();
31 if ($stream->isReadable()) {
32 $mode = $stream->isWritable() ? 'r+' : 'r';
33 } elseif ($stream->isWritable()) {
34 $mode = 'w';
35 } else {
36 throw new \InvalidArgumentException('The stream must be readable, ' . 'writable, or both.');
37 }
38 $resource = @\fopen('guzzle://stream', $mode, \false, self::createStreamContext($stream));
39 if ($resource === \false) {
40 throw new \RuntimeException('Unable to create stream resource');
41 }
42 return $resource;
43 }
44 /**
45 * Creates a stream context that can be used to open a stream as a php stream resource.
46 *
47 * @return resource
48 */
49 public static function createStreamContext(StreamInterface $stream)
50 {
51 return \stream_context_create(['guzzle' => ['stream' => $stream]]);
52 }
53 /**
54 * Registers the stream wrapper if needed
55 */
56 public static function register() : void
57 {
58 if (!\in_array('guzzle', \stream_get_wrappers())) {
59 \stream_wrapper_register('guzzle', __CLASS__);
60 }
61 }
62 public function stream_open(string $path, string $mode, int $options, ?string &$opened_path = null) : bool
63 {
64 $options = \stream_context_get_options($this->context);
65 $stream = $options['guzzle']['stream'] ?? null;
66 if (!$stream instanceof StreamInterface) {
67 return \false;
68 }
69 $this->mode = $mode;
70 $this->stream = $stream;
71 return \true;
72 }
73 /**
74 * @return string|false
75 */
76 public function stream_read(int $count)
77 {
78 try {
79 return $this->stream->read($count);
80 } catch (\RuntimeException $e) {
81 return \false;
82 }
83 }
84 public function stream_write(string $data) : int
85 {
86 try {
87 return $this->stream->write($data);
88 } catch (\RuntimeException $e) {
89 return -1;
90 }
91 }
92 /**
93 * @return int|false
94 */
95 public function stream_tell()
96 {
97 try {
98 return $this->stream->tell();
99 } catch (\RuntimeException $e) {
100 return \false;
101 }
102 }
103 public function stream_eof() : bool
104 {
105 try {
106 return $this->stream->eof();
107 } catch (\RuntimeException $e) {
108 return \true;
109 }
110 }
111 public function stream_seek(int $offset, int $whence) : bool
112 {
113 try {
114 $this->stream->seek($offset, $whence);
115 } catch (\RuntimeException $e) {
116 return \false;
117 }
118 return \true;
119 }
120 /**
121 * @return resource|false
122 */
123 public function stream_cast(int $cast_as)
124 {
125 try {
126 $stream = clone $this->stream;
127 $resource = $stream->detach();
128 } catch (\RuntimeException $e) {
129 return \false;
130 }
131 return $resource ?? \false;
132 }
133 /**
134 * @return array{
135 * dev: int,
136 * ino: int,
137 * mode: int,
138 * nlink: int,
139 * uid: int,
140 * gid: int,
141 * rdev: int,
142 * size: int,
143 * atime: int,
144 * mtime: int,
145 * ctime: int,
146 * blksize: int,
147 * blocks: int
148 * }|false
149 */
150 public function stream_stat()
151 {
152 try {
153 $size = $this->stream->getSize();
154 } catch (\RuntimeException $e) {
155 return \false;
156 }
157 if ($size === null) {
158 return \false;
159 }
160 static $modeMap = ['r' => 33060, 'rb' => 33060, 'r+' => 33206, 'w' => 33188, 'wb' => 33188];
161 return ['dev' => 0, 'ino' => 0, 'mode' => $modeMap[$this->mode] ?? 0, 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => $size, 'atime' => 0, 'mtime' => 0, 'ctime' => 0, 'blksize' => 0, 'blocks' => 0];
162 }
163 /**
164 * @return array{
165 * dev: int,
166 * ino: int,
167 * mode: int,
168 * nlink: int,
169 * uid: int,
170 * gid: int,
171 * rdev: int,
172 * size: int,
173 * atime: int,
174 * mtime: int,
175 * ctime: int,
176 * blksize: int,
177 * blocks: int
178 * }
179 */
180 public function url_stat(string $path, int $flags) : array
181 {
182 return ['dev' => 0, 'ino' => 0, 'mode' => 0, 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => 0, 'atime' => 0, 'mtime' => 0, 'ctime' => 0, 'blksize' => 0, 'blocks' => 0];
183 }
184 }
185