namespace Symfony\Component\Process;
+@trigger_error(sprintf('The %s class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the Process class instead.', ProcessBuilder::class), E_USER_DEPRECATED);
+
use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;
/**
- * Process builder.
- *
* @author Kris Wallsmith <kris@symfony.com>
+ *
+ * @deprecated since version 3.4, to be removed in 4.0. Use the Process class instead.
*/
class ProcessBuilder
{
private $env = array();
private $input;
private $timeout = 60;
- private $options = array();
+ private $options;
private $inheritEnv = true;
private $prefix = array();
private $outputDisabled = false;
/**
- * Constructor.
- *
* @param string[] $arguments An array of arguments
*/
public function __construct(array $arguments = array())
*/
public function setPrefix($prefix)
{
- $this->prefix = is_array($prefix) ? $prefix : array($prefix);
+ $this->prefix = \is_array($prefix) ? $prefix : array($prefix);
return $this;
}
/**
* Sets the working directory.
*
- * @param null|string $cwd The working directory
+ * @param string|null $cwd The working directory
*
* @return $this
*/
* defined environment variable.
*
* @param string $name The variable name
- * @param null|string $value The variable value
+ * @param string|null $value The variable value
*
* @return $this
*/
/**
* Sets the input of the process.
*
- * @param mixed $input The input as a string
+ * @param resource|string|int|float|bool|\Traversable|null $input The input content
*
* @return $this
*
* @throws InvalidArgumentException In case the argument is invalid
- *
- * Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.
*/
public function setInput($input)
{
*/
public function getProcess()
{
- if (0 === count($this->prefix) && 0 === count($this->arguments)) {
+ if (0 === \count($this->prefix) && 0 === \count($this->arguments)) {
throw new LogicException('You must add() command arguments before calling getProcess().');
}
- $options = $this->options;
-
$arguments = array_merge($this->prefix, $this->arguments);
- $script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));
+ $process = new Process($arguments, $this->cwd, $this->env, $this->input, $this->timeout, $this->options);
+ // to preserve the BC with symfony <3.3, we convert the array structure
+ // to a string structure to avoid the prefixing with the exec command
+ $process->setCommandLine($process->getCommandLine());
if ($this->inheritEnv) {
- // include $_ENV for BC purposes
- $env = array_replace($_ENV, $_SERVER, $this->env);
- } else {
- $env = $this->env;
+ $process->inheritEnvironmentVariables();
}
-
- $process = new Process($script, $this->cwd, $env, $this->input, $this->timeout, $options);
-
if ($this->outputDisabled) {
$process->disableOutput();
}