Skip to content

Commit 4d8578e

Browse files
committed
Minor refactoring
1 parent 1e42021 commit 4d8578e

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

src/Shell/Shell.php

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111

1212
class Shell {
1313

14-
private $command;
15-
private $cwd;
16-
private $descriptors;
17-
private $env;
18-
private $pipes;
19-
private $process;
20-
private $stdin;
21-
private $stdout;
22-
private $stderr;
23-
private $timeout;
14+
protected $command;
15+
protected $cwd;
16+
protected $descriptors;
17+
protected $env;
18+
protected $pipes;
19+
protected $process;
20+
protected $status;
21+
protected $stdin;
22+
protected $stdout;
23+
protected $stderr;
24+
protected $timeout;
2425

2526
public function __construct(string $command, string $cwd = null, $stdin = null, $env = null, $timeout = 60)
2627
{
@@ -47,11 +48,6 @@ public function execute()
4748
}
4849
}
4950

50-
public function stop()
51-
{
52-
return proc_close($this->process);
53-
}
54-
5551
public function getDescriptors()
5652
{
5753
return array(
@@ -61,31 +57,43 @@ public function getDescriptors()
6157
);
6258
}
6359

64-
public function kill()
65-
{
66-
return proc_terminate($this->process);
67-
}
68-
6960
public function setInput()
7061
{
7162
fwrite($this->pipes[0], $this->stdin);
72-
fclose($this->pipes[0]);
7363
}
7464

7565
public function getOutput()
7666
{
7767
$this->stdout = stream_get_contents($this->pipes[1]);
78-
fclose($this->pipes[1]);
68+
7969

8070
return $this->stdout;
8171
}
8272

73+
public function getStatus()
74+
{
75+
$this->status = proc_get_status($this->process);
76+
return $this->status;
77+
}
78+
8379
public function getErrorOutput()
8480
{
8581
$this->stderr = stream_get_contents($this->pipes[2]);
82+
return $this->stderr;
83+
}
84+
85+
public function stop()
86+
{
87+
fclose($this->pipes[0]);
88+
fclose($this->pipes[1]);
8689
fclose($this->pipes[2]);
90+
return proc_close($this->process);
91+
}
8792

88-
return $this->stderr;
93+
94+
public function kill()
95+
{
96+
return proc_terminate($this->process);
8997
}
9098

9199
public function __destruct()

0 commit comments

Comments
 (0)