LTSProcessBuilder.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Alchemy\Tests\BinaryDriver;
  3. use Alchemy\BinaryDriver\ProcessBuilderFactory;
  4. use LogicException;
  5. use Symfony\Component\Process\Process;
  6. use Symfony\Component\Process\ProcessBuilder;
  7. class LTSProcessBuilder extends ProcessBuilder
  8. {
  9. private $arguments;
  10. private $prefix;
  11. private $timeout;
  12. public function __construct(array $arguments = array())
  13. {
  14. $this->arguments = $arguments;
  15. parent::__construct($arguments);
  16. }
  17. public function setArguments(array $arguments)
  18. {
  19. $this->arguments = $arguments;
  20. return $this;
  21. }
  22. public function setPrefix($prefix)
  23. {
  24. $this->prefix = $prefix;
  25. return $this;
  26. }
  27. public function setTimeout($timeout)
  28. {
  29. $this->timeout = $timeout;
  30. return $this;
  31. }
  32. public function getProcess()
  33. {
  34. if (!$this->prefix && !count($this->arguments)) {
  35. throw new LogicException('You must add() command arguments before calling getProcess().');
  36. }
  37. $args = $this->prefix ? array_merge(array($this->prefix), $this->arguments) : $this->arguments;
  38. $script = implode(' ', array_map('escapeshellarg', $args));
  39. return new Process($script, null, null, null, $this->timeout);
  40. }
  41. }