ProcessBuilderFactory.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * This file is part of Zippy.
  4. *
  5. * (c) Alchemy <info@alchemy.fr>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Alchemy\Zippy\ProcessBuilder;
  11. use Alchemy\Zippy\Exception\InvalidArgumentException;
  12. use Symfony\Component\Process\ProcessBuilder;
  13. class ProcessBuilderFactory implements ProcessBuilderFactoryInterface
  14. {
  15. /**
  16. * The binary path
  17. *
  18. * @var String
  19. */
  20. protected $binary;
  21. /**
  22. * Constructor
  23. *
  24. * @param String $binary The path to the binary
  25. *
  26. * @throws InvalidArgumentException In case binary path is invalid
  27. */
  28. public function __construct($binary)
  29. {
  30. $this->useBinary($binary);
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function getBinary()
  36. {
  37. return $this->binary;
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function useBinary($binary)
  43. {
  44. if (!is_executable($binary)) {
  45. throw new InvalidArgumentException(sprintf('`%s` is not an executable binary', $binary));
  46. }
  47. $this->binary = $binary;
  48. return $this;
  49. }
  50. /**
  51. * @inheritdoc
  52. */
  53. public function create()
  54. {
  55. if (null === $this->binary) {
  56. throw new InvalidArgumentException('No binary set');
  57. }
  58. return ProcessBuilder::create(array($this->binary))->setTimeout(null);
  59. }
  60. }