|
7 | 7 | use Evenement\EventEmitter;
|
8 | 8 | use React\EventLoop\LoopInterface;
|
9 | 9 | use React\Stream\DuplexStreamInterface;
|
| 10 | +use React\Stream\ReadableResourceStream; |
10 | 11 | use React\Stream\ReadableStreamInterface;
|
11 | 12 | use React\Stream\Util;
|
| 13 | +use React\Stream\WritableResourceStream; |
12 | 14 | use React\Stream\WritableStreamInterface;
|
13 |
| -use React\Stream\Stream; |
14 | 15 |
|
15 | 16 | class Stdio extends EventEmitter implements DuplexStreamInterface
|
16 | 17 | {
|
@@ -268,21 +269,16 @@ private function restoreTtyMode()
|
268 | 269 | private function createStdin(LoopInterface $loop)
|
269 | 270 | {
|
270 | 271 | // STDIN not defined ("php -a") or already closed (`fclose(STDIN)`)
|
271 |
| - if (!defined('STDIN') || !is_resource(STDIN)) { |
272 |
| - $stream = new Stream(fopen('php://memory', 'r'), $loop); |
273 |
| - $stream->close(); |
274 |
| - return $stream; |
275 |
| - } |
276 |
| - |
277 |
| - $stream = new Stream(STDIN, $loop); |
278 |
| - |
279 |
| - // support starting program with closed STDIN ("example.php 0<&-") |
| 272 | + // also support starting program with closed STDIN ("example.php 0<&-") |
280 | 273 | // the stream is a valid resource and is not EOF, but fstat fails
|
281 |
| - if (fstat(STDIN) === false) { |
| 274 | + if (!defined('STDIN') || !is_resource(STDIN) || fstat(STDIN) === false) { |
| 275 | + $stream = new ReadableResourceStream(fopen('php://memory', 'r'), $loop); |
282 | 276 | $stream->close();
|
283 | 277 | return $stream;
|
284 | 278 | }
|
285 | 279 |
|
| 280 | + $stream = new ReadableResourceStream(STDIN, $loop); |
| 281 | + |
286 | 282 | if (function_exists('readline_callback_handler_install')) {
|
287 | 283 | // Prefer `ext-readline` to install dummy handler to turn on raw input mode.
|
288 | 284 | // We will nevery actually feed the readline handler and instead
|
@@ -313,12 +309,13 @@ private function createStdin(LoopInterface $loop)
|
313 | 309 | private function createStdout(LoopInterface $loop)
|
314 | 310 | {
|
315 | 311 | // STDOUT not defined ("php -a") or already closed (`fclose(STDOUT)`)
|
316 |
| - if (!defined('STDOUT') || !is_resource(STDOUT)) { |
317 |
| - $output = new Stream(fopen('php://memory', 'r+'), $loop); |
| 312 | + // also support starting program with closed STDOUT ("example.php >&-") |
| 313 | + // the stream is a valid resource and is not EOF, but fstat fails |
| 314 | + if (!defined('STDOUT') || !is_resource(STDOUT) || fstat(STDOUT) === false) { |
| 315 | + $output = new WritableResourceStream(fopen('php://memory', 'r+'), $loop); |
318 | 316 | $output->close();
|
319 | 317 | } else {
|
320 |
| - $output = new Stream(STDOUT, $loop); |
321 |
| - $output->pause(); |
| 318 | + $output = new WritableResourceStream(STDOUT, $loop); |
322 | 319 | }
|
323 | 320 |
|
324 | 321 | return $output;
|
|
0 commit comments