Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0991cd0

Browse files
committed
[Process] moved env check to the Process class (refs #8227)
1 parent 6089f32 commit 0991cd0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
145145
$this->cwd = getcwd();
146146
}
147147
if (null !== $env) {
148-
$this->env = array();
149-
foreach ($env as $key => $value) {
150-
$this->env[(binary) $key] = (binary) $value;
151-
}
148+
$this->setEnv($env);
152149
} else {
153150
$this->env = null;
154151
}
@@ -890,13 +887,25 @@ public function getEnv()
890887
/**
891888
* Sets the environment variables.
892889
*
890+
* An environment variable value should be a string.
891+
* If it is an array, the variable is ignored.
892+
*
893+
* That happens in PHP when 'argv' is registered into
894+
* the $_ENV array for instance.
895+
*
893896
* @param array $env The new environment variables
894897
*
895898
* @return self The current Process instance
896899
*/
897900
public function setEnv(array $env)
898901
{
899-
$this->env = $env;
902+
// Process can not handle env values that are arrays
903+
$env = array_filter($env, function ($value) { if (!is_array($value)) { return true; } });
904+
905+
$this->env = array();
906+
foreach ($env as $key => $value) {
907+
$this->env[(binary) $key] = (binary) $value;
908+
}
900909

901910
return $this;
902911
}

src/Symfony/Component/Process/ProcessBuilder.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ public function getProcess()
151151
$env = $this->env;
152152
}
153153

154-
// Process can not handle env values that are arrays
155-
$env = $env ? array_filter($env, function ($value) { if (!is_array($value)) { return true; } }) : $env;
156-
157154
return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
158155
}
159156
}

0 commit comments

Comments
 (0)