1
|
|
|
<?php |
2
|
|
|
namespace phpbu\App\Cli\Executable; |
3
|
|
|
|
4
|
|
|
use phpbu\App\Util\Cli; |
5
|
|
|
use SebastianFeldmann\Cli\CommandLine; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Execute Binary |
9
|
|
|
* |
10
|
|
|
* @package phpbu |
11
|
|
|
* @subpackage Backup |
12
|
|
|
* @author Sebastian Feldmann <[email protected]> |
13
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
14
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
15
|
|
|
* @link http://phpbu.de/ |
16
|
|
|
* @since Class available since Release 2.1.0 |
17
|
|
|
*/ |
18
|
|
|
abstract class Abstraction |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Command name. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $cmd; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* List of acceptable exit codes. |
29
|
|
|
* |
30
|
|
|
* @var int[] |
31
|
|
|
*/ |
32
|
|
|
protected $acceptableExitCodes = [0]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Absolute path to command. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $binary; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Command to execute |
43
|
|
|
* |
44
|
|
|
* @var \SebastianFeldmann\Cli\CommandLine |
45
|
|
|
*/ |
46
|
|
|
protected $commandLine; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Setup binary. |
50
|
|
|
* |
51
|
|
|
* @param string $cmd |
52
|
|
|
* @param string $path |
53
|
|
|
*/ |
54
|
214 |
|
protected function setup(string $cmd, string $path = '') { |
55
|
214 |
|
$this->cmd = $cmd; |
56
|
214 |
|
$this->binary = Cli::detectCmdLocation($cmd, $path, Cli::getCommandLocations($this->cmd)); |
57
|
214 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns the CommandLine for this command. |
61
|
|
|
* |
62
|
|
|
* @return \SebastianFeldmann\Cli\CommandLine |
63
|
|
|
*/ |
64
|
204 |
|
public function getCommandLine() : CommandLine |
65
|
|
|
{ |
66
|
204 |
|
return $this->createCommandLine(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* CommandLine generator. |
71
|
|
|
* |
72
|
|
|
* @return \SebastianFeldmann\Cli\CommandLine |
73
|
|
|
*/ |
74
|
|
|
abstract protected function createCommandLine() : CommandLine; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Return the command line to execute. |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
* @throws \phpbu\App\Exception |
81
|
|
|
*/ |
82
|
189 |
|
public function getCommand() : string |
83
|
|
|
{ |
84
|
189 |
|
return $this->getCommandLine()->getCommand(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns a lost of acceptable exit codes. |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
7 |
|
public function getAcceptableExitCodes() : array |
93
|
|
|
{ |
94
|
7 |
|
return $this->acceptableExitCodes; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Return the command with masked passwords or keys. |
99
|
|
|
* |
100
|
|
|
* By default just return the original command. Subclasses with password |
101
|
|
|
* arguments have to override this method. |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
11 |
|
public function getCommandPrintable() : string |
106
|
|
|
{ |
107
|
11 |
|
return $this->getCommand(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|