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