1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the SVN-Buddy library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy\Process; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use Symfony\Component\Process\PhpExecutableFinder; |
15
|
|
|
use Symfony\Component\Process\Process; |
16
|
|
|
|
17
|
|
|
class ProcessFactory implements IProcessFactory |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Creates new Symfony process with given arguments. |
22
|
|
|
* |
23
|
|
|
* @param array $command_line The command line to run. |
24
|
|
|
* @param integer|null $idle_timeout Idle timeout. |
25
|
|
|
* |
26
|
|
|
* @return Process |
27
|
|
|
*/ |
28
|
1 |
|
public function createProcess(array $command_line, $idle_timeout = null) |
29
|
|
|
{ |
30
|
1 |
|
$process = new Process($command_line); |
31
|
1 |
|
$process->setTimeout(null); |
32
|
1 |
|
$process->setIdleTimeout($idle_timeout); |
33
|
|
|
|
34
|
1 |
|
return $process; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Creates new Symfony PHP process with given arguments. |
39
|
|
|
* |
40
|
|
|
* @param string $command Command. |
41
|
|
|
* @param array $arguments Arguments. |
42
|
|
|
* |
43
|
|
|
* @return Process |
44
|
|
|
* @throws \RuntimeException When PHP executable can't be found. |
45
|
|
|
*/ |
46
|
1 |
|
public function createCommandProcess($command, array $arguments = array()) |
47
|
|
|
{ |
48
|
1 |
|
$php_executable_finder = new PhpExecutableFinder(); |
49
|
1 |
|
$php_executable = $php_executable_finder->find(); |
50
|
|
|
|
51
|
|
|
// @codeCoverageIgnoreStart |
52
|
|
|
if ( !$php_executable ) { |
53
|
|
|
throw new \RuntimeException('The PHP executable cannot be found.'); |
54
|
|
|
} |
55
|
|
|
// @codeCoverageIgnoreEnd |
56
|
|
|
|
57
|
1 |
|
array_unshift($arguments, $php_executable, $_SERVER['argv'][0], $command); |
58
|
|
|
|
59
|
1 |
|
return new Process($arguments); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|