1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Consolidation\SiteProcess; |
4
|
|
|
|
5
|
|
|
use Psr\Log\LoggerInterface; |
6
|
|
|
use Symfony\Component\Process\Process; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* A wrapper around Symfony Process. |
10
|
|
|
* |
11
|
|
|
* - Supports simulated mode. Typically enabled via a --simulate option. |
12
|
|
|
* - Supports verbose mode - logs all runs. |
13
|
|
|
*/ |
14
|
|
|
class ProcessBase extends Process |
15
|
|
|
{ |
16
|
|
|
private $simulated = false; |
17
|
|
|
|
18
|
|
|
private $verbose = false; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var LoggerInterface |
22
|
|
|
*/ |
23
|
|
|
private $logger; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return bool |
27
|
|
|
*/ |
28
|
|
|
public function getVerbose() |
29
|
|
|
{ |
30
|
|
|
return $this->verbose; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param bool $verbose |
35
|
|
|
*/ |
36
|
|
|
public function setVerbose($verbose) |
37
|
|
|
{ |
38
|
|
|
$this->verbose = $verbose; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
|
|
public function getSimulated() |
45
|
|
|
{ |
46
|
|
|
return $this->simulated; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param bool $simulated |
51
|
|
|
*/ |
52
|
|
|
public function setSimulated($simulated) |
53
|
|
|
{ |
54
|
|
|
$this->simulated = $simulated; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return LoggerInterface |
59
|
|
|
*/ |
60
|
|
|
public function getLogger() |
61
|
|
|
{ |
62
|
|
|
return $this->logger; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param LoggerInterface $logger |
67
|
|
|
*/ |
68
|
|
|
public function setLogger($logger) |
69
|
|
|
{ |
70
|
|
|
$this->logger = $logger; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritDoc |
75
|
|
|
*/ |
76
|
|
|
public function start(callable $callback = null) |
77
|
|
|
{ |
78
|
|
|
$cmd = $this->getCommandLine(); |
79
|
|
|
if ($this->getSimulated()) { |
80
|
|
|
$this->getLogger()->notice('Simulating: ' . $cmd); |
81
|
|
|
// Run a command that always succeeds. |
82
|
|
|
$this->setCommandLine('exit 0'); |
83
|
|
|
} elseif ($this->getVerbose()) { |
84
|
|
|
$this->getLogger()->info('Executing: ' . $cmd); |
85
|
|
|
} |
86
|
|
|
parent::start($callback); |
87
|
|
|
// Set command back to original value in case anyone asks. |
88
|
|
|
if ($this->getSimulated()) { |
89
|
|
|
$this->setCommandLine($cmd); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|