PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/sdk/google/guzzlehttp/psr7/src/Stream.php +35 -35 1.1.1 → 1.4.2 View file →
@@ -1,10 +1,10 @@
1 1 <?php
2 2
3 3 declare (strict_types=1);
4 -namespace Dudlewebs\WPMCS\GuzzleHttp\Psr7;
4 +namespace Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7;
5 5
6 -use Dudlewebs\WPMCS\Psr\Http\Message\StreamInterface;
6 +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\StreamInterface;
7 7 /**
8 8 * PHP stream implementation.
9 9 */
10 10 class Stream implements StreamInterface
@@ -12,10 +12,10 @@
12 12 /**
13 13 * @see https://www.php.net/manual/en/function.fopen.php
14 14 * @see https://www.php.net/manual/en/function.gzopen.php
15 15 */
16 - private const READABLE_MODES = '/r|a\+|ab\+|w\+|wb\+|x\+|xb\+|c\+|cb\+/';
17 - private const WRITABLE_MODES = '/a|w|r\+|rb\+|rw|x|c/';
16 + private const READABLE_MODES = '/r|a\\+|ab\\+|w\\+|wb\\+|x\\+|xb\\+|c\\+|cb\\+/';
17 + private const WRITABLE_MODES = '/a|w|r\\+|rb\\+|rw|x|c/';
18 18 /** @var resource */
19 19 private $stream;
20 20 /** @var int|null */
21 21 private $size;
@@ -44,9 +44,9 @@
44 44 * @throws \InvalidArgumentException if the stream is not a stream resource
45 45 */
46 46 public function __construct($stream, array $options = [])
47 47 {
48 - if (!is_resource($stream)) {
48 + if (!\is_resource($stream)) {
49 49 throw new \InvalidArgumentException('Stream must be a resource');
50 50 }
51 51 if (isset($options['size'])) {
52 52 $this->size = $options['size'];
@@ -52,12 +52,12 @@
52 52 $this->size = $options['size'];
53 53 }
54 54 $this->customMetadata = $options['metadata'] ?? [];
55 55 $this->stream = $stream;
56 - $meta = stream_get_meta_data($this->stream);
56 + $meta = \stream_get_meta_data($this->stream);
57 57 $this->seekable = $meta['seekable'];
58 - $this->readable = (bool) preg_match(self::READABLE_MODES, $meta['mode']);
59 - $this->writable = (bool) preg_match(self::WRITABLE_MODES, $meta['mode']);
58 + $this->readable = (bool) \preg_match(self::READABLE_MODES, $meta['mode']);
59 + $this->writable = (bool) \preg_match(self::WRITABLE_MODES, $meta['mode']);
60 60 $this->uri = $this->getMetadata('uri');
61 61 }
62 62 /**
63 63 * Closes the stream when the destructed
@@ -65,9 +65,9 @@
65 65 public function __destruct()
66 66 {
67 67 $this->close();
68 68 }
69 - public function __toString(): string
69 + public function __toString() : string
70 70 {
71 71 try {
72 72 if ($this->isSeekable()) {
73 73 $this->seek(0);
@@ -76,13 +76,13 @@
76 76 } catch (\Throwable $e) {
77 77 if (\PHP_VERSION_ID >= 70400) {
78 78 throw $e;
79 79 }
80 - trigger_error(sprintf('%s::__toString exception: %s', self::class, (string) $e), \E_USER_ERROR);
80 + \trigger_error(\sprintf('%s::__toString exception: %s', self::class, (string) $e), \E_USER_ERROR);
81 81 return '';
82 82 }
83 83 }
84 - public function getContents(): string
84 + public function getContents() : string
85 85 {
86 86 if (!isset($this->stream)) {
87 87 throw new \RuntimeException('Stream is detached');
88 88 }
@@ -90,13 +90,13 @@
90 90 throw new \RuntimeException('Cannot read from non-readable stream');
91 91 }
92 92 return Utils::tryGetContents($this->stream);
93 93 }
94 - public function close(): void
94 + public function close() : void
95 95 {
96 96 if (isset($this->stream)) {
97 - if (is_resource($this->stream)) {
98 - fclose($this->stream);
97 + if (\is_resource($this->stream)) {
98 + \fclose($this->stream);
99 99 }
100 100 $this->detach();
101 101 }
102 102 }
@@ -110,9 +110,9 @@
110 110 $this->size = $this->uri = null;
111 111 $this->readable = $this->writable = $this->seekable = \false;
112 112 return $result;
113 113 }
114 - public function getSize(): ?int
114 + public function getSize() : ?int
115 115 {
116 116 if ($this->size !== null) {
117 117 return $this->size;
118 118 }
@@ -120,52 +120,52 @@
120 120 return null;
121 121 }
122 122 // Clear the stat cache if the stream has a URI
123 123 if ($this->uri) {
124 - clearstatcache(\true, $this->uri);
124 + \clearstatcache(\true, $this->uri);
125 125 }
126 - $stats = fstat($this->stream);
127 - if (is_array($stats) && isset($stats['size'])) {
126 + $stats = \fstat($this->stream);
127 + if (\is_array($stats) && isset($stats['size'])) {
128 128 $this->size = $stats['size'];
129 129 return $this->size;
130 130 }
131 131 return null;
132 132 }
133 - public function isReadable(): bool
133 + public function isReadable() : bool
134 134 {
135 135 return $this->readable;
136 136 }
137 - public function isWritable(): bool
137 + public function isWritable() : bool
138 138 {
139 139 return $this->writable;
140 140 }
141 - public function isSeekable(): bool
141 + public function isSeekable() : bool
142 142 {
143 143 return $this->seekable;
144 144 }
145 - public function eof(): bool
145 + public function eof() : bool
146 146 {
147 147 if (!isset($this->stream)) {
148 148 throw new \RuntimeException('Stream is detached');
149 149 }
150 - return feof($this->stream);
150 + return \feof($this->stream);
151 151 }
152 - public function tell(): int
152 + public function tell() : int
153 153 {
154 154 if (!isset($this->stream)) {
155 155 throw new \RuntimeException('Stream is detached');
156 156 }
157 - $result = ftell($this->stream);
157 + $result = \ftell($this->stream);
158 158 if ($result === \false) {
159 159 throw new \RuntimeException('Unable to determine stream position');
160 160 }
161 161 return $result;
162 162 }
163 - public function rewind(): void
163 + public function rewind() : void
164 164 {
165 165 $this->seek(0);
166 166 }
167 - public function seek($offset, $whence = \SEEK_SET): void
167 + public function seek($offset, $whence = \SEEK_SET) : void
168 168 {
169 169 $whence = (int) $whence;
170 170 if (!isset($this->stream)) {
171 171 throw new \RuntimeException('Stream is detached');
@@ -172,13 +172,13 @@
172 172 }
173 173 if (!$this->seekable) {
174 174 throw new \RuntimeException('Stream is not seekable');
175 175 }
176 - if (fseek($this->stream, $offset, $whence) === -1) {
177 - throw new \RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . var_export($whence, \true));
176 + if (\fseek($this->stream, $offset, $whence) === -1) {
177 + throw new \RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . \var_export($whence, \true));
178 178 }
179 179 }
180 - public function read($length): string
180 + public function read($length) : string
181 181 {
182 182 if (!isset($this->stream)) {
183 183 throw new \RuntimeException('Stream is detached');
184 184 }
@@ -191,9 +191,9 @@
191 191 if (0 === $length) {
192 192 return '';
193 193 }
194 194 try {
195 - $string = fread($this->stream, $length);
195 + $string = \fread($this->stream, $length);
196 196 } catch (\Exception $e) {
197 197 throw new \RuntimeException('Unable to read from stream', 0, $e);
198 198 }
199 199 if (\false === $string) {
@@ -200,9 +200,9 @@
200 200 throw new \RuntimeException('Unable to read from stream');
201 201 }
202 202 return $string;
203 203 }
204 - public function write($string): int
204 + public function write($string) : int
205 205 {
206 206 if (!isset($this->stream)) {
207 207 throw new \RuntimeException('Stream is detached');
208 208 }
@@ -210,9 +210,9 @@
210 210 throw new \RuntimeException('Cannot write to a non-writable stream');
211 211 }
212 212 // We can't know the size after writing anything
213 213 $this->size = null;
214 - $result = fwrite($this->stream, $string);
214 + $result = \fwrite($this->stream, $string);
215 215 if ($result === \false) {
216 216 throw new \RuntimeException('Unable to write to stream');
217 217 }
218 218 return $result;
@@ -224,12 +224,12 @@
224 224 {
225 225 if (!isset($this->stream)) {
226 226 return $key ? null : [];
227 227 } elseif (!$key) {
228 - return $this->customMetadata + stream_get_meta_data($this->stream);
228 + return $this->customMetadata + \stream_get_meta_data($this->stream);
229 229 } elseif (isset($this->customMetadata[$key])) {
230 230 return $this->customMetadata[$key];
231 231 }
232 - $meta = stream_get_meta_data($this->stream);
232 + $meta = \stream_get_meta_data($this->stream);
233 233 return $meta[$key] ?? null;
234 234 }
235 235 }