Symfony\Component\Process\Process::setEnv PHP Method

setEnv() public method

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.
public setEnv ( array $env ) : self
$env array The new environment variables
return self The current Process instance
    public function setEnv(array $env)
    {
        // Process can not handle env values that are arrays
        $env = array_filter($env, function ($value) {
            return !is_array($value);
        });
        $this->env = array();
        foreach ($env as $key => $value) {
            $this->env[$key] = (string) $value;
        }
        return $this;
    }

Usage Example

Example #1
0
File: Exec.php Project: jjok/Robo
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->printAction();
     $this->process = new Process($this->getCommand());
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (isset($this->env)) {
         $this->process->setEnv($this->env);
     }
     if (!$this->background and !$this->isPrinted) {
         $this->startTimer();
         $this->process->run();
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     if (!$this->background and $this->isPrinted) {
         $this->startTimer();
         $this->process->run(function ($type, $buffer) {
             $progressWasVisible = $this->hideTaskProgress();
             print $buffer;
             $this->showTaskProgress($progressWasVisible);
         });
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::fromException($this, $e);
     }
     return Result::success($this);
 }
All Usage Examples Of Symfony\Component\Process\Process::setEnv