Skip to content

Commit

Permalink
Moved public functions to the bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
sushilkg committed Sep 1, 2018
1 parent 87ed2e4 commit 22a759a
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions src/Shell/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,35 @@ public function __construct($command, $cwd = null, $input = null, $env = null, $
$this->timeout = $timeout;
}

public function execute()
private function getDescriptors()
{
return array(
self::STDIN_DESCRIPTOR_KEY => array("pipe", "r"),
self::STDOUT_DESCRIPTOR_KEY => array("pipe", "w"),
self::STDERR_DESCRIPTOR_KEY => array("pipe", "r")
);
}

private function setInput()
{
$this->start();
$this->wait();
fwrite($this->pipes[self::STDIN_DESCRIPTOR_KEY], $this->input);
}

private function start()
private function updateStatus()
{
$this->status = proc_get_status($this->process);

return $this->status;
}

private function closePipes()
{
fclose($this->pipes[self::STDIN_DESCRIPTOR_KEY]);
fclose($this->pipes[self::STDOUT_DESCRIPTOR_KEY]);
fclose($this->pipes[self::STDERR_DESCRIPTOR_KEY]);
}

public function execute(bool $blocking = false)
{
if ($this->isRunning()) {
throw new RuntimeException('Process is already running');
Expand All @@ -65,20 +87,10 @@ private function start()

$this->startTime = microtime(true);
$this->status = $this->updateStatus();
}

private function getDescriptors()
{
return array(
self::STDIN_DESCRIPTOR_KEY => array("pipe", "r"),
self::STDOUT_DESCRIPTOR_KEY => array("pipe", "w"),
self::STDERR_DESCRIPTOR_KEY => array("pipe", "r")
);
}

private function setInput()
{
fwrite($this->pipes[self::STDIN_DESCRIPTOR_KEY], $this->input);
if ($blocking) {
$this->wait();
}
}

public function getOutput()
Expand Down Expand Up @@ -109,13 +121,6 @@ public function checkTimeout()
return $this->status;
}

private function updateStatus()
{
$this->status = proc_get_status($this->process);

return $this->status;
}

public function wait()
{
while ($this->isRunning()) {
Expand All @@ -135,7 +140,7 @@ public function isRunning()
public function stop()
{
if (!$this->isRunning()) {
throw new RuntimeException("No process to stop");
return $this->getExitCode();
}

$this->closePipes();
Expand All @@ -145,13 +150,6 @@ public function stop()
return $this->getExitCode();
}

private function closePipes()
{
fclose($this->pipes[self::STDIN_DESCRIPTOR_KEY]);
fclose($this->pipes[self::STDOUT_DESCRIPTOR_KEY]);
fclose($this->pipes[self::STDERR_DESCRIPTOR_KEY]);
}

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

0 comments on commit 22a759a

Please sign in to comment.