@@ -31,6 +31,10 @@ final class FileReadTrapStreamWrapper
31
31
32
32
public static ?string $ autoloadLocatedFile = null ;
33
33
34
+ private bool $ readFromFile = false ;
35
+
36
+ private int $ seekPosition = 0 ;
37
+
34
38
/**
35
39
* @param string[] $streamWrapperProtocols
36
40
*
@@ -85,6 +89,8 @@ public static function withStreamWrapperOverride(
85
89
public function stream_open ($ path , $ mode , $ options , &$ openedPath ): bool
86
90
{
87
91
self ::$ autoloadLocatedFile = $ path ;
92
+ $ this ->readFromFile = false ;
93
+ $ this ->seekPosition = 0 ;
88
94
89
95
return true ;
90
96
}
@@ -99,6 +105,8 @@ public function stream_open($path, $mode, $options, &$openedPath): bool
99
105
*/
100
106
public function stream_read ($ count ): string
101
107
{
108
+ $ this ->readFromFile = true ;
109
+
102
110
// Dummy return value that is also valid PHP for require(). We'll read
103
111
// and process the file elsewhere, so it's OK to provide dummy data for
104
112
// this read.
@@ -173,4 +181,64 @@ public function url_stat($path, $flags)
173
181
return $ result ;
174
182
}
175
183
184
+ /**
185
+ * Simulates behavior of reading from an empty file.
186
+ *
187
+ * @return bool
188
+ */
189
+ public function stream_eof (): bool
190
+ {
191
+ return $ this ->readFromFile ;
192
+ }
193
+
194
+ public function stream_flush (): bool
195
+ {
196
+ return true ;
197
+ }
198
+
199
+ public function stream_tell (): int
200
+ {
201
+ return $ this ->seekPosition ;
202
+ }
203
+
204
+ /**
205
+ * @param int $offset
206
+ * @param int $whence
207
+ * @return bool
208
+ */
209
+ public function stream_seek ($ offset , $ whence ): bool
210
+ {
211
+ switch ($ whence ) {
212
+ // Behavior is the same for a zero-length file
213
+ case SEEK_SET :
214
+ case SEEK_END :
215
+ if ($ offset < 0 ) {
216
+ return false ;
217
+ }
218
+ $ this ->seekPosition = $ offset ;
219
+ return true ;
220
+
221
+ case SEEK_CUR :
222
+ if ($ offset < 0 ) {
223
+ return false ;
224
+ }
225
+ $ this ->seekPosition += $ offset ;
226
+ return true ;
227
+
228
+ default :
229
+ return false ;
230
+ }
231
+ }
232
+
233
+ /**
234
+ * @param int $option
235
+ * @param int $arg1
236
+ * @param int $arg2
237
+ * @return bool
238
+ */
239
+ public function stream_set_option ($ option , $ arg1 , $ arg2 ): bool
240
+ {
241
+ return false ;
242
+ }
243
+
176
244
}
0 commit comments