@@ -25,18 +25,20 @@ class Server
2525 /** @var Shell */
2626 protected $ shell ;
2727
28- /** @var OutputInterface */
28+ /** @var BufferedOutput */
2929 protected $ output ;
3030
31- public function __construct ($ host , Shell $ shell , OutputInterface $ output , LoopInterface $ loop = null )
32- {
33- $ loop = $ loop ?? Factory::create ();
31+ /** @var Stdio */
32+ protected $ stdio ;
3433
34+ public function __construct ($ host , Shell $ shell , BufferedOutput $ output , LoopInterface $ loop = null , Stdio $ stdio = null )
35+ {
3536 $ this ->host = $ host ;
36- $ this ->loop = $ loop ;
37+ $ this ->loop = $ loop ?? Factory:: create () ;
3738 $ this ->shell = $ shell ;
3839 $ this ->output = $ output ;
3940 $ this ->shellOutput = new BufferedOutput ();
41+ $ this ->stdio = $ stdio ?? $ this ->createStdio ();
4042 }
4143
4244 public function start ()
@@ -45,8 +47,6 @@ public function start()
4547
4648 $ this ->createSocketServer ();
4749
48- $ this ->createStdio ();
49-
5050 $ this ->loop ->run ();
5151 }
5252
@@ -60,20 +60,22 @@ protected function createSocketServer()
6060
6161 $ this ->shell ->setScopeVariables (array_merge ($ unserializedData , $ this ->shell ->getScopeVariables ()));
6262
63- $ this ->output ->write (PHP_EOL );
63+ $ this ->stdio ->write (PHP_EOL );
6464
6565 collect ($ unserializedData )->keys ()->map (function ($ variableName ) {
6666 $ this ->output ->writeln ('>> $ ' .$ variableName );
6767
6868 $ this ->executeCode ('$ ' .$ variableName );
6969
7070 $ this ->output ->write ($ this ->shellOutput ->fetch ());
71+
72+ $ this ->stdio ->write ($ this ->output ->fetch ());
7173 });
7274 });
7375 });
7476 }
7577
76- protected function createStdio ()
78+ protected function createStdio (): Stdio
7779 {
7880 $ stdio = new Stdio ($ this ->loop );
7981
@@ -87,7 +89,11 @@ protected function createStdio()
8789 $ this ->executeCode ($ line );
8890
8991 $ this ->output ->write (PHP_EOL .$ this ->shellOutput ->fetch ());
92+
93+ $ this ->stdio ->write ($ this ->output ->fetch ());
9094 });
95+
96+ return $ stdio ;
9197 }
9298
9399 protected function executeCode ($ code )
0 commit comments