Skip to content

Commit

Permalink
[Process] moved env check to the Process class (refs #8227)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 13, 2013
1 parent ac06e1b commit de78e86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 14 additions & 5 deletions Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
$this->cwd = getcwd();
}
if (null !== $env) {
$this->env = array();
foreach ($env as $key => $value) {
$this->env[(binary) $key] = (binary) $value;
}
$this->setEnv($env);
} else {
$this->env = null;
}
Expand Down Expand Up @@ -890,13 +887,25 @@ public function getEnv()
/**
* Sets the environment variables.
*
* An environment variable value should be a string.
* If it is an array, the variable is ignored.
*
* That happens in PHP when 'argv' is registered into
* the $_ENV array for instance.
*
* @param array $env The new environment variables
*
* @return self The current Process instance
*/
public function setEnv(array $env)
{
$this->env = $env;
// Process can not handle env values that are arrays
$env = array_filter($env, function ($value) { if (!is_array($value)) { return true; } });

$this->env = array();
foreach ($env as $key => $value) {
$this->env[(binary) $key] = (binary) $value;
}

return $this;
}
Expand Down
3 changes: 0 additions & 3 deletions ProcessBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ public function getProcess()
$env = $this->env;
}

// Process can not handle env values that are arrays
$env = $env ? array_filter($env, function ($value) { if (!is_array($value)) { return true; } }) : $env;

return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
}
}

0 comments on commit de78e86

Please sign in to comment.