22
33namespace Clue \React \Stdio ;
44
5- use React \Stream \StreamInterface ;
65use React \Stream \CompositeStream ;
76use React \EventLoop \LoopInterface ;
8- use React \Stream \ReadableStream ;
9- use React \Stream \Stream ;
7+ use React \Stream \ReadableStreamInterface ;
8+ use React \Stream \WritableStreamInterface ;
109
1110class Stdio extends CompositeStream
1211{
@@ -16,13 +15,23 @@ class Stdio extends CompositeStream
1615 private $ readline ;
1716 private $ needsNewline = false ;
1817
19- public function __construct (LoopInterface $ loop , $ input = true )
18+ public function __construct (LoopInterface $ loop , ReadableStreamInterface $ input = null , WritableStreamInterface $ output = null , Readline $ readline = null )
2019 {
21- $ this ->input = new Stdin ($ loop );
20+ if ($ input === null ) {
21+ $ input = new Stdin ($ loop );
22+ }
23+
24+ if ($ output === null ) {
25+ $ output = new Stdout (STDOUT );
26+ }
2227
23- $ this ->output = new Stdout (STDOUT );
28+ if ($ readline === null ) {
29+ $ readline = new Readline ($ input , $ output );
30+ }
2431
25- $ this ->readline = new Readline ($ this ->input , $ this ->output );
32+ $ this ->input = $ input ;
33+ $ this ->output = $ output ;
34+ $ this ->readline = $ readline ;
2635
2736 $ that = $ this ;
2837
@@ -35,10 +44,6 @@ public function __construct(LoopInterface $loop, $input = true)
3544 $ this ->readline ->on ('data ' , function ($ line ) use ($ that ) {
3645 $ that ->emit ('line ' , array ($ line , $ that ));
3746 });
38-
39- if (!$ input ) {
40- $ this ->pause ();
41- }
4247 }
4348
4449 public function pause ()
0 commit comments