Add ProcessBuilder::setPrefix method
This commit is contained in:
parent
a7c9863b3a
commit
cab53ee102
@ -28,6 +28,7 @@ class ProcessBuilder
|
|||||||
private $timeout;
|
private $timeout;
|
||||||
private $options;
|
private $options;
|
||||||
private $inheritEnv;
|
private $inheritEnv;
|
||||||
|
private $prefix;
|
||||||
|
|
||||||
public function __construct(array $arguments = array())
|
public function __construct(array $arguments = array())
|
||||||
{
|
{
|
||||||
@ -58,6 +59,22 @@ class ProcessBuilder
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an unescaped prefix to the command string.
|
||||||
|
*
|
||||||
|
* The prefix is preserved when reseting arguments.
|
||||||
|
*
|
||||||
|
* @param string $prefix A command prefix
|
||||||
|
*
|
||||||
|
* @return ProcessBuilder
|
||||||
|
*/
|
||||||
|
public function setPrefix($prefix)
|
||||||
|
{
|
||||||
|
$this->prefix = $prefix;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $arguments
|
* @param array $arguments
|
||||||
*
|
*
|
||||||
@ -143,7 +160,8 @@ class ProcessBuilder
|
|||||||
|
|
||||||
$options = $this->options;
|
$options = $this->options;
|
||||||
|
|
||||||
$script = implode(' ', array_map('escapeshellarg', $this->arguments));
|
$script = ($this->prefix ? escapeshellarg($this->prefix) . ' ' : '')
|
||||||
|
. implode(' ', array_map('escapeshellarg', $this->arguments));
|
||||||
|
|
||||||
if ($this->inheritEnv) {
|
if ($this->inheritEnv) {
|
||||||
$env = $this->env ? $this->env + $_ENV : null;
|
$env = $this->env ? $this->env + $_ENV : null;
|
||||||
|
@ -115,4 +115,16 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertContains("second", $proc->getCommandLine());
|
$this->assertContains("second", $proc->getCommandLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPrefixIsPrependedToAllGeneratedProcess()
|
||||||
|
{
|
||||||
|
$pb = new ProcessBuilder();
|
||||||
|
$pb->setPrefix('/usr/bin/php');
|
||||||
|
|
||||||
|
$proc = $pb->setArguments(array('-v'))->getProcess();
|
||||||
|
$this->assertEquals("'/usr/bin/php' '-v'", $proc->getCommandLine());
|
||||||
|
|
||||||
|
$proc = $pb->setArguments(array('-i'))->getProcess();
|
||||||
|
$this->assertEquals("'/usr/bin/php' '-i'", $proc->getCommandLine());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user