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.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / ecommerce / PaymentGateways / Paypal / vendor / guzzlehttp / psr7 / src / AppendStream.php
tutor / ecommerce / PaymentGateways / Paypal / vendor / guzzlehttp / psr7 / src Last commit date
Exception 1 year ago AppendStream.php 2 months ago BufferStream.php 2 months ago CachingStream.php 2 months ago DroppingStream.php 2 months ago FnStream.php 2 months ago Header.php 2 months ago HttpFactory.php 1 year ago InflateStream.php 1 year ago LazyOpenStream.php 1 year ago LimitStream.php 2 months ago Message.php 2 months ago MessageTrait.php 2 months ago MimeType.php 2 months ago MultipartStream.php 2 months ago NoSeekStream.php 2 months ago PumpStream.php 2 months ago Query.php 1 year ago Request.php 2 months ago Response.php 2 months ago Rfc3986.php 2 months ago Rfc7230.php 2 months ago ServerRequest.php 2 months ago Stream.php 2 months ago StreamDecoratorTrait.php 2 months ago StreamWrapper.php 2 months ago UploadedFile.php 2 months ago Uri.php 2 months ago UriComparator.php 2 months ago UriNormalizer.php 2 months ago UriResolver.php 2 months ago Utils.php 2 months ago
AppendStream.php
298 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace GuzzleHttp\Psr7;
6
7 use Psr\Http\Message\StreamInterface;
8
9 /**
10 * Reads from multiple streams, one after the other.
11 *
12 * This is a read-only stream decorator.
13 */
14 final class AppendStream implements StreamInterface
15 {
16 /** @var StreamInterface[] Streams being decorated */
17 private $streams = [];
18
19 /** @var bool */
20 private $seekable = true;
21
22 /** @var int */
23 private $current = 0;
24
25 /** @var int */
26 private $pos = 0;
27
28 /**
29 * @param StreamInterface[] $streams Streams to decorate. Each stream must
30 * be readable.
31 */
32 public function __construct(array $streams = [])
33 {
34 foreach ($streams as $stream) {
35 $this->addStream($stream);
36 }
37 }
38
39 public function __toString(): string
40 {
41 try {
42 $this->rewind();
43
44 return $this->getContents();
45 } catch (\Throwable $e) {
46 if (\PHP_VERSION_ID >= 70400) {
47 throw $e;
48 }
49 trigger_error(sprintf('%s::__toString exception: %s', self::class, (string) $e), E_USER_ERROR);
50
51 return '';
52 }
53 }
54
55 /**
56 * Add a stream to the AppendStream
57 *
58 * @param StreamInterface $stream Stream to append. Must be readable.
59 *
60 * @throws \InvalidArgumentException if the stream is not readable
61 */
62 public function addStream(StreamInterface $stream): void
63 {
64 if (!$stream->isReadable()) {
65 throw new \InvalidArgumentException('Each stream must be readable');
66 }
67
68 // The stream is only seekable if all streams are seekable
69 if (!$stream->isSeekable()) {
70 $this->seekable = false;
71 }
72
73 $this->streams[] = $stream;
74 }
75
76 public function getContents(): string
77 {
78 return Utils::copyToString($this);
79 }
80
81 /**
82 * Closes each attached stream.
83 */
84 public function close(): void
85 {
86 $this->pos = $this->current = 0;
87 $this->seekable = true;
88
89 foreach ($this->streams as $stream) {
90 $stream->close();
91 }
92
93 $this->streams = [];
94 }
95
96 /**
97 * Detaches each attached stream.
98 *
99 * Returns null as it's not clear which underlying stream resource to return.
100 */
101 public function detach()
102 {
103 $this->pos = $this->current = 0;
104 $this->seekable = true;
105
106 foreach ($this->streams as $stream) {
107 $stream->detach();
108 }
109
110 $this->streams = [];
111
112 return null;
113 }
114
115 public function tell(): int
116 {
117 return $this->pos;
118 }
119
120 /**
121 * Tries to calculate the size by adding the size of each stream.
122 *
123 * If any of the streams do not return a valid number, then the size of the
124 * append stream cannot be determined and null is returned.
125 */
126 public function getSize(): ?int
127 {
128 $size = 0;
129
130 foreach ($this->streams as $stream) {
131 $s = $stream->getSize();
132 if ($s === null) {
133 return null;
134 }
135 $size += $s;
136 }
137
138 return $size;
139 }
140
141 public function eof(): bool
142 {
143 return !$this->streams
144 || ($this->current >= count($this->streams) - 1
145 && $this->streams[$this->current]->eof());
146 }
147
148 public function rewind(): void
149 {
150 $this->seek(0);
151 }
152
153 /**
154 * Attempts to seek to the given position. Only supports SEEK_SET.
155 */
156 public function seek($offset, $whence = SEEK_SET): void
157 {
158 if (!\is_int($offset)) {
159 \trigger_deprecation(
160 'guzzlehttp/psr7',
161 '2.11',
162 'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
163 \get_debug_type($offset)
164 );
165 }
166
167 if (!\is_int($whence)) {
168 \trigger_deprecation(
169 'guzzlehttp/psr7',
170 '2.11',
171 'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
172 \get_debug_type($whence)
173 );
174 }
175
176 if (!$this->seekable) {
177 throw new \RuntimeException('This AppendStream is not seekable');
178 } elseif ($whence !== SEEK_SET) {
179 throw new \RuntimeException('The AppendStream can only seek with SEEK_SET');
180 }
181
182 $this->pos = $this->current = 0;
183
184 // Rewind each stream
185 foreach ($this->streams as $i => $stream) {
186 try {
187 $stream->rewind();
188 } catch (\Exception $e) {
189 throw new \RuntimeException('Unable to seek stream '
190 .$i.' of the AppendStream', 0, $e);
191 }
192 }
193
194 // Seek to the actual position by reading from each stream
195 while ($this->pos < $offset && !$this->eof()) {
196 $result = $this->read(min(8096, $offset - $this->pos));
197 if ($result === '') {
198 break;
199 }
200 }
201 }
202
203 /**
204 * Reads from all of the appended streams until the length is met or EOF.
205 */
206 public function read($length): string
207 {
208 if (!\is_int($length)) {
209 \trigger_deprecation(
210 'guzzlehttp/psr7',
211 '2.11',
212 'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
213 \get_debug_type($length)
214 );
215 }
216
217 if ($this->streams === []) {
218 return '';
219 }
220
221 $buffer = '';
222 $total = count($this->streams) - 1;
223 $remaining = $length;
224 $progressToNext = false;
225
226 while ($remaining > 0) {
227 // Progress to the next stream if needed.
228 if ($progressToNext || $this->streams[$this->current]->eof()) {
229 $progressToNext = false;
230 if ($this->current === $total) {
231 break;
232 }
233 ++$this->current;
234 }
235
236 $result = $this->streams[$this->current]->read($remaining);
237
238 if ($result === '') {
239 $progressToNext = true;
240 continue;
241 }
242
243 $buffer .= $result;
244 $remaining = $length - strlen($buffer);
245 }
246
247 $this->pos += strlen($buffer);
248
249 return $buffer;
250 }
251
252 public function isReadable(): bool
253 {
254 return true;
255 }
256
257 public function isWritable(): bool
258 {
259 return false;
260 }
261
262 public function isSeekable(): bool
263 {
264 return $this->seekable;
265 }
266
267 public function write($string): int
268 {
269 if (!\is_string($string)) {
270 \trigger_deprecation(
271 'guzzlehttp/psr7',
272 '2.11',
273 'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.',
274 \get_debug_type($string)
275 );
276 }
277
278 throw new \RuntimeException('Cannot write to an AppendStream');
279 }
280
281 /**
282 * @return mixed
283 */
284 public function getMetadata($key = null)
285 {
286 if ($key !== null && !\is_string($key)) {
287 \trigger_deprecation(
288 'guzzlehttp/psr7',
289 '2.11',
290 'Passing %s to StreamInterface::getMetadata() is deprecated; guzzlehttp/psr7 3.0 requires string|null for $key.',
291 \get_debug_type($key)
292 );
293 }
294
295 return $key ? null : [];
296 }
297 }
298