[Process] moved env check to the Process class (refs #8227)

This commit is contained in:
Fabien Potencier 2013-06-13 08:50:29 +02:00
parent 6089f32d61
commit 0991cd0b9d
2 changed files with 14 additions and 8 deletions

View File

@ -145,10 +145,7 @@ class Process
$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;
}
@ -890,13 +887,25 @@ class Process
/**
* 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;
}

View File

@ -151,9 +151,6 @@ class ProcessBuilder
$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);
}
}