Skip to content

Commit

Permalink
Using constants for descriptors key
Browse files Browse the repository at this point in the history
  • Loading branch information
sushilkg committed Sep 1, 2018
1 parent 4d8578e commit bd54feb
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/Shell/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@

class Shell {

const STDIN = 0;
const STDOUT = 1;
const STDERR = 2;

protected $command;
protected $cwd;
protected $descriptors;
protected $env;
protected $input;
protected $output;
protected $pipes;
protected $process;
protected $status;
protected $stdin;
protected $stdout;
protected $stderr;
protected $error;
protected $timeout;

public function __construct(string $command, string $cwd = null, $stdin = null, $env = null, $timeout = 60)
public function __construct(string $command, string $cwd = null, $input = null, $env = null, $timeout = 60)
{
if (!\function_exists('proc_open')) {
throw new RuntimeException('Required proc_open could not be found in your PHP setup');
Expand All @@ -33,7 +37,7 @@ public function __construct(string $command, string $cwd = null, $stdin = null,
$this->cwd = $cwd;
$this->descriptors = $this->getDescriptors();
$this->env = $env;
$this->stdin = $stdin;
$this->input = $input;
$this->timeout = $timeout;
}

Expand All @@ -51,23 +55,23 @@ public function execute()
public function getDescriptors()
{
return array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/error-output.txt", "a")
self::STDIN => array("pipe", "r"),
self::STDOUT => array("pipe", "w"),
self::STDERR => array("pipe", "r")
);
}

public function setInput()
{
fwrite($this->pipes[0], $this->stdin);
fwrite($this->pipes[0], $this->input);
}

public function getOutput()
{
$this->stdout = stream_get_contents($this->pipes[1]);
$this->output = stream_get_contents($this->pipes[1]);


return $this->stdout;
return $this->output;
}

public function getStatus()
Expand All @@ -78,8 +82,8 @@ public function getStatus()

public function getErrorOutput()
{
$this->stderr = stream_get_contents($this->pipes[2]);
return $this->stderr;
$this->error = stream_get_contents($this->pipes[2]);
return $this->error;
}

public function stop()
Expand All @@ -90,7 +94,6 @@ public function stop()
return proc_close($this->process);
}


public function kill()
{
return proc_terminate($this->process);
Expand Down

0 comments on commit bd54feb

Please sign in to comment.