symfony/symfony — pull request #7584 by romainneutron (2013-04-06 19:41:13+00:00)
Title: [Process] Add ProcessBuilder::setPrefix method

| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT

This introduce a new feature for the `ProcessBuilder` that allows to prefix all generated `Process` commands with a custom value.
This is mostly useful when dealing with binary drivers.

Use case :

```php
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\ProcessBuilder;

class PhpDriver
{
private $pb;

public function __construct(ProcessBuilder $pb)
{
$this->pb = $pb;
}

public function getInfos()
{
return $this->execute('-i');
}

public function getVersion()
{
return $this->execute('-v');
}

private function execute(array $arguments)
{
return $this
->pb
->setArguments($arguments)
->getProcess()
->run()
->getOutput();
}
}

$finder = new ExecutableFinder();

$pb = new ProcessBuilder();
$pb->setPrefix($finder->find('php'));

$driver = new PhpDriver($pb);
$driver->getVersion();
$driver->getInfos();
```