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