Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: dd48f892b4
Fetching contributors…

Cannot retrieve contributors at this time

113 lines (84 sloc) 2.448 kb
<?php
require_once "process.php";
class ProcessBuilder
{
private static $isWindows;
private $arguments;
private $cwd;
private $env;
private $stdin;
private $timeout = 60;
private $options = array();
private $inheritEnv = false;
public function __construct(array $arguments = array())
{
$this->arguments = $arguments;
if (null === self::$isWindows) {
self::$isWindows = defined('PHP_WINDOWS_VERSION_MAJOR');
}
}
/**
* Adds an unescaped argument to the command string.
*
* @param string $argument A command argument
*/
public function add($argument)
{
$this->arguments[] = $argument;
return $this;
}
public function setWorkingDirectory($cwd)
{
$this->cwd = $cwd;
return $this;
}
public function inheritEnvironmentVariables($inheritEnv = true)
{
$this->inheritEnv = $inheritEnv;
return $this;
}
public function setEnv($name, $value)
{
if (null === $this->env) {
$this->env = array();
}
$this->env[$name] = $value;
return $this;
}
public function setInput($stdin)
{
$this->stdin = $stdin;
return $this;
}
public function setTimeout($timeout)
{
$this->timeout = $timeout;
return $this;
}
public function setOption($name, $value)
{
$this->options[$name] = $value;
return $this;
}
public function getProcess()
{
if (!count($this->arguments)) {
throw new LogicException('You must add() command arguments before calling getProcess().');
}
$options = $this->options;
if (self::$isWindows) {
$options += array('bypass_shell' => true);
$args = $this->arguments;
$cmd = array_shift($args);
$script = '"'.$cmd.'"';
if ($args) {
$script .= ' '.implode(' ', array_map('escapeshellarg', $args));
}
$script = 'cmd /V:ON /E:ON /C "'.$script.'"';
} else {
$script = implode(' ', array_map('escapeshellarg', $this->arguments));
}
$env = $this->inheritEnv && $_ENV ? ($this->env ? $this->env : array()) + $_ENV : $this->env;
return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
}
}
Jump to Line
Something went wrong with that request. Please try again.