[Process] moved env check to the Process class (refs #8227)
This commit is contained in:
parent
6089f32d61
commit
0991cd0b9d
|
@ -145,10 +145,7 @@ class Process
|
||||||
$this->cwd = getcwd();
|
$this->cwd = getcwd();
|
||||||
}
|
}
|
||||||
if (null !== $env) {
|
if (null !== $env) {
|
||||||
$this->env = array();
|
$this->setEnv($env);
|
||||||
foreach ($env as $key => $value) {
|
|
||||||
$this->env[(binary) $key] = (binary) $value;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$this->env = null;
|
$this->env = null;
|
||||||
}
|
}
|
||||||
|
@ -890,13 +887,25 @@ class Process
|
||||||
/**
|
/**
|
||||||
* Sets the environment variables.
|
* 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
|
* @param array $env The new environment variables
|
||||||
*
|
*
|
||||||
* @return self The current Process instance
|
* @return self The current Process instance
|
||||||
*/
|
*/
|
||||||
public function setEnv(array $env)
|
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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,9 +151,6 @@ class ProcessBuilder
|
||||||
$env = $this->env;
|
$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);
|
return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue