16
16
use Psr \Http \Message \StreamInterface ;
17
17
use RuntimeException ;
18
18
19
+ use function clearstatcache ;
20
+ use function fclose ;
21
+ use function feof ;
22
+ use function fopen ;
23
+ use function fread ;
24
+ use function fseek ;
25
+ use function fstat ;
26
+ use function ftell ;
27
+ use function fwrite ;
28
+ use function is_resource ;
29
+ use function is_string ;
30
+ use function stream_get_contents ;
31
+ use function stream_get_meta_data ;
32
+ use function var_export ;
33
+
19
34
use const SEEK_CUR ;
20
35
use const SEEK_SET ;
21
36
@@ -100,17 +115,17 @@ public static function create($body = ''): StreamInterface
100
115
return $ body ;
101
116
}
102
117
103
- if (\ is_string ($ body )) {
104
- $ resource = \ fopen ('php://temp ' , 'rw+ ' );
105
- \ fwrite ($ resource , $ body );
118
+ if (is_string ($ body )) {
119
+ $ resource = fopen ('php://temp ' , 'rw+ ' );
120
+ fwrite ($ resource , $ body );
106
121
$ body = $ resource ;
107
122
}
108
123
109
- if (\ is_resource ($ body )) {
124
+ if (is_resource ($ body )) {
110
125
$ new = new self ();
111
126
$ new ->stream = $ body ;
112
- $ meta = \ stream_get_meta_data ($ new ->stream );
113
- $ new ->seekable = $ meta ['seekable ' ] && \ fseek ($ new ->stream , 0 , SEEK_CUR ) === 0 ;
127
+ $ meta = stream_get_meta_data ($ new ->stream );
128
+ $ new ->seekable = $ meta ['seekable ' ] && fseek ($ new ->stream , 0 , SEEK_CUR ) === 0 ;
114
129
$ new ->readable = isset (self ::READ_WRITE_HASH ['read ' ][$ meta ['mode ' ]]);
115
130
$ new ->writable = isset (self ::READ_WRITE_HASH ['write ' ][$ meta ['mode ' ]]);
116
131
$ new ->uri = $ new ->getMetadata ('uri ' );
@@ -124,8 +139,8 @@ public static function create($body = ''): StreamInterface
124
139
public function close (): void
125
140
{
126
141
if (isset ($ this ->stream )) {
127
- if (\ is_resource ($ this ->stream )) {
128
- \ fclose ($ this ->stream );
142
+ if (is_resource ($ this ->stream )) {
143
+ fclose ($ this ->stream );
129
144
}
130
145
$ this ->detach ();
131
146
}
@@ -157,10 +172,10 @@ public function getSize(): ?int
157
172
158
173
// Clear the stat cache if the stream has a URI
159
174
if ($ this ->uri ) {
160
- \ clearstatcache (true , $ this ->uri );
175
+ clearstatcache (true , $ this ->uri );
161
176
}
162
177
163
- $ stats = \ fstat ($ this ->stream );
178
+ $ stats = fstat ($ this ->stream );
164
179
if (isset ($ stats ['size ' ])) {
165
180
$ this ->size = $ stats ['size ' ];
166
181
@@ -172,7 +187,7 @@ public function getSize(): ?int
172
187
173
188
public function tell (): int
174
189
{
175
- if (false === $ result = \ ftell ($ this ->stream )) {
190
+ if (false === $ result = ftell ($ this ->stream )) {
176
191
throw new RuntimeException ('Unable to determine stream position ' );
177
192
}
178
193
@@ -181,7 +196,7 @@ public function tell(): int
181
196
182
197
public function eof (): bool
183
198
{
184
- return ! $ this ->stream || \ feof ($ this ->stream );
199
+ return ! $ this ->stream || feof ($ this ->stream );
185
200
}
186
201
187
202
public function isSeekable (): bool
@@ -195,8 +210,8 @@ public function seek($offset, $whence = SEEK_SET): void
195
210
throw new RuntimeException ('Stream is not seekable ' );
196
211
}
197
212
198
- if (\ fseek ($ this ->stream , $ offset , $ whence ) === -1 ) {
199
- throw new RuntimeException ('Unable to seek to stream position ' . $ offset . ' with whence ' . \ var_export ($ whence , true ));
213
+ if (fseek ($ this ->stream , $ offset , $ whence ) === -1 ) {
214
+ throw new RuntimeException ('Unable to seek to stream position ' . $ offset . ' with whence ' . var_export ($ whence , true ));
200
215
}
201
216
}
202
217
@@ -219,7 +234,7 @@ public function write($string): int
219
234
// We can't know the size after writing anything
220
235
$ this ->size = null ;
221
236
222
- if (false === $ result = \ fwrite ($ this ->stream , $ string )) {
237
+ if (false === $ result = fwrite ($ this ->stream , $ string )) {
223
238
throw new RuntimeException ('Unable to write to stream ' );
224
239
}
225
240
@@ -237,7 +252,7 @@ public function read($length): string
237
252
throw new RuntimeException ('Cannot read from non-readable stream ' );
238
253
}
239
254
240
- return \ fread ($ this ->stream , $ length );
255
+ return fread ($ this ->stream , $ length );
241
256
}
242
257
243
258
public function getContents (): string
@@ -246,7 +261,7 @@ public function getContents(): string
246
261
throw new RuntimeException ('Unable to read stream contents ' );
247
262
}
248
263
249
- if (false === $ contents = \ stream_get_contents ($ this ->stream )) {
264
+ if (false === $ contents = stream_get_contents ($ this ->stream )) {
250
265
throw new RuntimeException ('Unable to read stream contents ' );
251
266
}
252
267
@@ -259,7 +274,7 @@ public function getMetadata($key = null)
259
274
return $ key ? null : [];
260
275
}
261
276
262
- $ meta = \ stream_get_meta_data ($ this ->stream );
277
+ $ meta = stream_get_meta_data ($ this ->stream );
263
278
264
279
if ($ key === null ) {
265
280
return $ meta ;
0 commit comments