1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* this file is part of pipelines */ |
4
|
|
|
|
5
|
|
|
namespace Ktomk\Pipelines\Runner; |
6
|
|
|
|
7
|
|
|
use Ktomk\Pipelines\Utility\Options; |
8
|
|
|
use Ktomk\Pipelines\Value\Prefix; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Runner options parameter object |
12
|
|
|
*/ |
13
|
|
|
class RunOpts |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $prefix; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Options |
22
|
|
|
*/ |
23
|
|
|
private $options; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $binaryPackage; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var null|string of step expression or null if not set |
32
|
|
|
*/ |
33
|
|
|
private $steps; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var bool |
37
|
|
|
*/ |
38
|
|
|
private $noManual = false; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var null|string --user $(id -u):$(id -g) |
42
|
|
|
*/ |
43
|
|
|
private $user; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var null|true --ssh-auth |
47
|
|
|
*/ |
48
|
|
|
private $ssh; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Static factory method |
52
|
|
|
* |
53
|
|
|
* @param string $prefix [optional] |
54
|
|
|
* @param string $binaryPackage [optional] package name or path to binary (string) |
55
|
|
|
* @param Options $options [optional] |
56
|
|
|
* |
57
|
|
|
* @return RunOpts |
58
|
|
|
*/ |
59
|
1 |
|
public static function create($prefix = null, $binaryPackage = null, Options $options = null) |
60
|
|
|
{ |
61
|
1 |
|
null === $options && $options = Options::create(); |
62
|
|
|
|
63
|
1 |
|
return new self($prefix, $options, $binaryPackage); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* RunOpts constructor. |
68
|
|
|
* |
69
|
|
|
* NOTE: All run options are optional by design (pass NULL). |
70
|
|
|
* |
71
|
|
|
* @param string $prefix |
72
|
|
|
* @param null|Options $options |
73
|
|
|
* @param string $binaryPackage package name or path to binary (string) |
74
|
|
|
* @param null|string $user user option, non-null (string) if set |
75
|
|
|
* @param null|true $ssh |
76
|
|
|
*/ |
77
|
2 |
|
public function __construct($prefix = null, Options $options = null, $binaryPackage = null, $user = null, $ssh = null) |
78
|
|
|
{ |
79
|
2 |
|
$this->prefix = null === $prefix ? $prefix : Prefix::verify($prefix); |
80
|
2 |
|
$this->options = $options; |
81
|
2 |
|
$this->binaryPackage = $binaryPackage; |
82
|
2 |
|
$this->user = $user; |
83
|
2 |
|
$this->ssh = $ssh; |
84
|
2 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $prefix |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
1 |
|
public function setPrefix($prefix) |
92
|
|
|
{ |
93
|
1 |
|
$this->prefix = $prefix; |
94
|
1 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* The prefix is used when creating containers for the container name. |
98
|
|
|
* |
99
|
|
|
* See --prefix option. |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
1 |
|
public function getPrefix() |
104
|
|
|
{ |
105
|
1 |
|
return $this->prefix; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param string $name |
110
|
|
|
* |
111
|
|
|
* @return null|string |
112
|
|
|
*/ |
113
|
2 |
|
public function getOption($name) |
114
|
|
|
{ |
115
|
2 |
|
if (!isset($this->options)) { |
116
|
1 |
|
return null; |
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
return $this->options->get($name); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $name |
124
|
|
|
* |
125
|
|
|
* @return bool |
126
|
|
|
*/ |
127
|
1 |
|
public function getBoolOption($name) |
128
|
|
|
{ |
129
|
1 |
|
return (bool)$this->getOption($name); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $binaryPackage |
134
|
|
|
* |
135
|
|
|
* @return void |
136
|
|
|
*/ |
137
|
1 |
|
public function setBinaryPackage($binaryPackage) |
138
|
|
|
{ |
139
|
1 |
|
$this->binaryPackage = $binaryPackage; |
140
|
1 |
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
1 |
|
public function getBinaryPackage() |
146
|
|
|
{ |
147
|
1 |
|
return $this->binaryPackage; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return null|string |
152
|
|
|
*/ |
153
|
1 |
|
public function getSteps() |
154
|
|
|
{ |
155
|
1 |
|
return $this->steps; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param null|string $steps |
160
|
|
|
* |
161
|
|
|
* @return void |
162
|
|
|
*/ |
163
|
1 |
|
public function setSteps($steps) |
164
|
|
|
{ |
165
|
1 |
|
$this->steps = $steps; |
166
|
1 |
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return bool |
170
|
|
|
*/ |
171
|
1 |
|
public function isNoManual() |
172
|
|
|
{ |
173
|
1 |
|
return $this->noManual; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param bool $noManual |
178
|
|
|
* |
179
|
|
|
* @return void |
180
|
|
|
*/ |
181
|
1 |
|
public function setNoManual($noManual) |
182
|
|
|
{ |
183
|
1 |
|
$this->noManual = (bool)$noManual; |
184
|
1 |
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return null|string |
188
|
|
|
*/ |
189
|
1 |
|
public function getUser() |
190
|
|
|
{ |
191
|
1 |
|
return $this->user; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param null|string $user |
196
|
|
|
*/ |
197
|
1 |
|
public function setUser($user) |
198
|
|
|
{ |
199
|
1 |
|
$this->user = $user; |
200
|
1 |
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return null|true |
204
|
|
|
*/ |
205
|
1 |
|
public function getSsh() |
206
|
|
|
{ |
207
|
1 |
|
return $this->ssh ? true : null; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param null|true $ssh |
212
|
|
|
*/ |
213
|
1 |
|
public function setSsh($ssh) |
214
|
|
|
{ |
215
|
1 |
|
$this->ssh = $ssh ? true : null; |
216
|
1 |
|
} |
217
|
|
|
} |
218
|
|
|
|