Skip to content

Commit

Permalink
fixed cs
Browse files Browse the repository at this point in the history
  • Loading branch information
drak3 committed Mar 23, 2012
1 parent af65673 commit f9f51a5
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -159,7 +159,8 @@ public function run($callback = null)

/**
* Starts the process and returns after sending the stdin.
* This method blocks until all stdin data is sent to the process then it returns while the pricess runs in the background.
*
* This method blocks until all stdin data is sent to the process then it returns while the process runs in the background.
* The termination of the process can be awaited with waitForTermination
*
* The callback receives the type of output (out or err) and
Expand All @@ -176,7 +177,7 @@ public function run($callback = null)
*/
public function start($callback = null)
{
if($this->isRunning()) {
if ($this->isRunning()) {
throw new \RuntimeException('Process is already running');
}
$this->stdout = '';
Expand Down Expand Up @@ -204,7 +205,7 @@ public function start($callback = null)
stream_set_blocking($pipe, false);
}

if(null === $this->stdin) {
if (null === $this->stdin) {
fclose($this->pipes[0]);

return;
Expand Down Expand Up @@ -265,7 +266,6 @@ public function start($callback = null)
* from the independent process during execution.
*
* @param Closure|string|array $callback
* @param boolean $invokeCallbackWithStartData
* @return int the exitcode of the process
* @throws \RuntimeException
*/
Expand All @@ -282,7 +282,8 @@ public function waitForTermination($callback = null)

if (false === $n) {
break;
} elseif ($n === 0) {
}
if (0 === $n) {
proc_terminate($this->process);

throw new \RuntimeException('The process timed out.');
Expand All @@ -302,7 +303,7 @@ public function waitForTermination($callback = null)
}
$this->updateStatus();
if ($this->processInformation['signaled']) {
throw new \RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
throw new \RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
}

$time = 0;
Expand Down Expand Up @@ -461,8 +462,9 @@ public function getStopSignal()
* Returns if the process is currently running
* @return boolean
*/
public function isRunning() {
if(self::STATUS_STARTED === $this->status) {
public function isRunning()
{
if (self::STATUS_STARTED === $this->status) {
$this->updateStatus();
if($this->processInformation['running'] === false) {
$this->status = self::STATUS_TERMINATED;
Expand All @@ -480,9 +482,10 @@ public function isRunning() {
* @return int the exitcode of the process
* @throws \RuntimeException if the process got signaled
*/
public function stop($timeout=10) {
public function stop($timeout=10)
{
$timeoutMicro = (int) $timeout*10E6;
if($this->isRunning()) {
if ($this->isRunning()) {
proc_terminate($this->process);
$time = 0;
while (1 == $this->isRunning() && $time < $timeoutMicro) {
Expand Down Expand Up @@ -608,25 +611,25 @@ protected function buildCallback($callback) {
*/
protected function updateStatus()
{
if(self::STATUS_STARTED === $this->status) {
if (self::STATUS_STARTED === $this->status) {
$this->processInformation = proc_get_status($this->process);
if(!$this->processInformation['running']) {
if (!$this->processInformation['running']) {
$this->status = self::STATUS_TERMINATED;
if(-1 !== $this->processInformation['exitcode']) {
if (-1 !== $this->processInformation['exitcode']) {
$this->exitcode = $this->processInformation['exitcode'];
}
}
}
}

protected function updateErrorOutput() {
if(isset($this->pipes[self::STDERR]) && is_resource($this->pipes[self::STDERR])) {
if (isset($this->pipes[self::STDERR]) && is_resource($this->pipes[self::STDERR])) {
$this->addErrorOutput(stream_get_contents($this->pipes[self::STDERR]));
}
}

protected function updateOutput() {
if(isset($this->pipes[self::STDOUT]) && is_resource($this->pipes[self::STDOUT])) {
if (isset($this->pipes[self::STDOUT]) && is_resource($this->pipes[self::STDOUT])) {
$this->addOutput(stream_get_contents($this->pipes[self::STDOUT]));
}
}
Expand Down

0 comments on commit f9f51a5

Please sign in to comment.