-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathMemoryRunner.php
More file actions
80 lines (64 loc) · 1.68 KB
/
MemoryRunner.php
File metadata and controls
80 lines (64 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace CzProject\GitPhp\Runners;
use CzProject\GitPhp\CommandProcessor;
use CzProject\GitPhp\GitException;
use CzProject\GitPhp\IRunner;
use CzProject\GitPhp\RunnerResult;
class MemoryRunner implements IRunner
{
/** @var string */
private $cwd;
/** @var CommandProcessor */
private $commandProcessor;
/** @var array<string, RunnerResult> [command => RunnerResult] */
private $results = [];
/**
* @param string $cwd
*/
public function __construct($cwd)
{
$this->cwd = $cwd;
$this->commandProcessor = new CommandProcessor;
}
/**
* Add a configuration parameter to the command.
* @param string $name
* @param mixed $value
*/
public function addConfig($name, $value)
{
$this->commandProcessor->addConfig($name, $value);
}
/**
* @param array<mixed> $args
* @param array<string, scalar> $env
* @param array<string> $output
* @param array<string> $errorOutput
* @param int $exitCode
* @return self
*/
public function setResult(array $args, array $env, array $output, array $errorOutput = [], $exitCode = 0)
{
$cmd = $this->commandProcessor->process('git', $args, $env);
$this->results[$cmd] = new RunnerResult($cmd, $exitCode, $output, $errorOutput);
return $this;
}
/**
* @return RunnerResult
*/
public function run($cwd, array $args, array $env = NULL)
{
$cmd = $this->commandProcessor->process('git', $args, $env);
if (!isset($this->results[$cmd])) {
throw new \CzProject\GitPhp\InvalidStateException("Missing result for command '$cmd'.");
}
return $this->results[$cmd];
}
/**
* @return string
*/
public function getCwd()
{
return $this->cwd;
}
}