11
11
12
12
class Shell {
13
13
14
+ const STDIN = 0 ;
15
+ const STDOUT = 1 ;
16
+ const STDERR = 2 ;
17
+
14
18
protected $ command ;
15
19
protected $ cwd ;
16
20
protected $ descriptors ;
17
21
protected $ env ;
22
+ protected $ input ;
23
+ protected $ output ;
18
24
protected $ pipes ;
19
25
protected $ process ;
20
26
protected $ status ;
21
- protected $ stdin ;
22
- protected $ stdout ;
23
- protected $ stderr ;
27
+ protected $ error ;
24
28
protected $ timeout ;
25
29
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 )
27
31
{
28
32
if (!\function_exists ('proc_open ' )) {
29
33
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,
33
37
$ this ->cwd = $ cwd ;
34
38
$ this ->descriptors = $ this ->getDescriptors ();
35
39
$ this ->env = $ env ;
36
- $ this ->stdin = $ stdin ;
40
+ $ this ->input = $ input ;
37
41
$ this ->timeout = $ timeout ;
38
42
}
39
43
@@ -51,23 +55,23 @@ public function execute()
51
55
public function getDescriptors ()
52
56
{
53
57
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 " )
57
61
);
58
62
}
59
63
60
64
public function setInput ()
61
65
{
62
- fwrite ($ this ->pipes [0 ], $ this ->stdin );
66
+ fwrite ($ this ->pipes [0 ], $ this ->input );
63
67
}
64
68
65
69
public function getOutput ()
66
70
{
67
- $ this ->stdout = stream_get_contents ($ this ->pipes [1 ]);
71
+ $ this ->output = stream_get_contents ($ this ->pipes [1 ]);
68
72
69
73
70
- return $ this ->stdout ;
74
+ return $ this ->output ;
71
75
}
72
76
73
77
public function getStatus ()
@@ -78,8 +82,8 @@ public function getStatus()
78
82
79
83
public function getErrorOutput ()
80
84
{
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 ;
83
87
}
84
88
85
89
public function stop ()
@@ -90,7 +94,6 @@ public function stop()
90
94
return proc_close ($ this ->process );
91
95
}
92
96
93
-
94
97
public function kill ()
95
98
{
96
99
return proc_terminate ($ this ->process );
0 commit comments