From 0991cd0b9df3158a23d8a95e2981e3cac3db74fc Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 13 Jun 2013 08:50:29 +0200 Subject: [PATCH] [Process] moved env check to the Process class (refs #8227) --- src/Symfony/Component/Process/Process.php | 19 ++++++++++++++----- .../Component/Process/ProcessBuilder.php | 3 --- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index ac92467574..ed4cccff3c 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -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; } diff --git a/src/Symfony/Component/Process/ProcessBuilder.php b/src/Symfony/Component/Process/ProcessBuilder.php index 151340d336..c4ef31d311 100644 --- a/src/Symfony/Component/Process/ProcessBuilder.php +++ b/src/Symfony/Component/Process/ProcessBuilder.php @@ -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); } }