1111
1212 class Shell {
1313
14+ const STDIN = 0 ;
15+ const STDOUT = 1 ;
16+ const STDERR = 2 ;
17+
1418 protected $ command ;
1519 protected $ cwd ;
1620 protected $ descriptors ;
1721 protected $ env ;
22+ protected $ input ;
23+ protected $ output ;
1824 protected $ pipes ;
1925 protected $ process ;
2026 protected $ status ;
21- protected $ stdin ;
22- protected $ stdout ;
23- protected $ stderr ;
27+ protected $ error ;
2428 protected $ timeout ;
2529
26- public function __construct (string $ command , string $ cwd = null , $ stdin = null , $ env = null , $ timeout = 60 )
30+ public function __construct (string $ command , string $ cwd = null , $ input = null , $ env = null , $ timeout = 60 )
2731 {
2832 if (!\function_exists ('proc_open ' )) {
2933 throw new RuntimeException ('Required proc_open could not be found in your PHP setup ' );
@@ -33,7 +37,7 @@ public function __construct(string $command, string $cwd = null, $stdin = null,
3337 $ this ->cwd = $ cwd ;
3438 $ this ->descriptors = $ this ->getDescriptors ();
3539 $ this ->env = $ env ;
36- $ this ->stdin = $ stdin ;
40+ $ this ->input = $ input ;
3741 $ this ->timeout = $ timeout ;
3842 }
3943
@@ -51,23 +55,23 @@ public function execute()
5155 public function getDescriptors ()
5256 {
5357 return array (
54- 0 => array ("pipe " , "r " ),
55- 1 => array ("pipe " , "w " ),
56- 2 => array ("file " , "/tmp/error-output.txt " , " a " )
58+ self :: STDIN => array ("pipe " , "r " ),
59+ self :: STDOUT => array ("pipe " , "w " ),
60+ self :: STDERR => array ("pipe " , "r " )
5761 );
5862 }
5963
6064 public function setInput ()
6165 {
62- fwrite ($ this ->pipes [0 ], $ this ->stdin );
66+ fwrite ($ this ->pipes [0 ], $ this ->input );
6367 }
6468
6569 public function getOutput ()
6670 {
67- $ this ->stdout = stream_get_contents ($ this ->pipes [1 ]);
71+ $ this ->output = stream_get_contents ($ this ->pipes [1 ]);
6872
6973
70- return $ this ->stdout ;
74+ return $ this ->output ;
7175 }
7276
7377 public function getStatus ()
@@ -78,8 +82,8 @@ public function getStatus()
7882
7983 public function getErrorOutput ()
8084 {
81- $ this ->stderr = stream_get_contents ($ this ->pipes [2 ]);
82- return $ this ->stderr ;
85+ $ this ->error = stream_get_contents ($ this ->pipes [2 ]);
86+ return $ this ->error ;
8387 }
8488
8589 public function stop ()
@@ -90,7 +94,6 @@ public function stop()
9094 return proc_close ($ this ->process );
9195 }
9296
93-
9497 public function kill ()
9598 {
9699 return proc_terminate ($ this ->process );
0 commit comments