Completed
Push — master ( 68693d...b79797 )
by Adam
12:25
created

ProcessHelper::createProcessBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\CoreBundle\Helper\Process;
14
15
use Symfony\Component\Process\Process;
16
use Symfony\Component\Process\ProcessBuilder;
17
18
/**
19
 * Class ProcessHelper
20
 *
21
 * @author  Adam Piotrowski <[email protected]>
22
 */
23
final class ProcessHelper implements ProcessHelperInterface
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $phpBinaryPath;
29
    
30
    /**
31
     * @var string
32
     */
33
    protected $cwd;
34
    
35
    public function __construct(string $phpBinaryPath, string $cwd)
36
    {
37
        $this->phpBinaryPath = $phpBinaryPath;
38
        $this->cwd           = $cwd;
39
    }
40
    
41
    public function createProcess(array $arguments, int $timeout = 720): Process
42
    {
43
        $command = $this->createProcessBuilder($arguments, $timeout)->getProcess()->getCommandLine();
44
        $process = new Process($command, $this->cwd);
45
        $process->setTimeout($timeout);
46
        
47
        return $process;
48
    }
49
    
50
    public function createProcessBuilder(array $arguments, $timeout = 720): ProcessBuilder
51
    {
52
        $builder = new ProcessBuilder();
53
        $builder->setPrefix($this->phpBinaryPath);
54
        $builder->setWorkingDirectory($this->cwd);
55
        $builder->setArguments($arguments);
56
        $builder->setTimeout($timeout);
57
        $builder->inheritEnvironmentVariables(true);
58
        
59
        return $builder;
60
    }
61
}
62
63