|
1
|
|
|
<?php |
|
2
|
|
|
namespace phpbu\App; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Configuration |
|
6
|
|
|
* |
|
7
|
|
|
* @package phpbu |
|
8
|
|
|
* @subpackage App |
|
9
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
10
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
|
11
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
12
|
|
|
* @link http://phpbu.de/ |
|
13
|
|
|
* @since Class available since Release 1.0.0 |
|
14
|
|
|
*/ |
|
15
|
|
|
class Configuration |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Filename |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $filename = ''; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Path to bootstrap file. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $bootstrap = ''; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Verbose output |
|
33
|
|
|
* |
|
34
|
|
|
* @var bool |
|
35
|
|
|
*/ |
|
36
|
|
|
private $verbose = false; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Use colors in output. |
|
40
|
|
|
* |
|
41
|
|
|
* @var bool |
|
42
|
|
|
*/ |
|
43
|
|
|
private $colors = false; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Output debug information |
|
47
|
|
|
* |
|
48
|
|
|
* @var boolean |
|
49
|
|
|
*/ |
|
50
|
|
|
private $debug = false; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Don't execute anything just pretend to |
|
54
|
|
|
* |
|
55
|
|
|
* @var bool |
|
56
|
|
|
*/ |
|
57
|
|
|
private $simulate = false; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Show how to restore the backup |
|
61
|
|
|
* |
|
62
|
|
|
* @var bool |
|
63
|
|
|
*/ |
|
64
|
|
|
private $restore = false; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* List of logger configurations |
|
68
|
|
|
* |
|
69
|
|
|
* @var array |
|
70
|
|
|
*/ |
|
71
|
|
|
private $loggers = []; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* List of backup configurations |
|
75
|
|
|
* |
|
76
|
|
|
* @var array |
|
77
|
|
|
*/ |
|
78
|
|
|
private $backups = []; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* List of backus to execute |
|
82
|
|
|
* |
|
83
|
|
|
* @var array |
|
84
|
|
|
*/ |
|
85
|
|
|
private $limit = []; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Working directory |
|
89
|
|
|
* |
|
90
|
|
|
* @var string |
|
91
|
|
|
*/ |
|
92
|
|
|
private static $workingDirectory; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Filename setter. |
|
96
|
|
|
* |
|
97
|
|
|
* @param string $file |
|
98
|
|
|
*/ |
|
99
|
44 |
|
public function setFilename(string $file) |
|
100
|
|
|
{ |
|
101
|
44 |
|
$this->filename = $file; |
|
102
|
44 |
|
self::setWorkingDirectory(dirname($file)); |
|
103
|
44 |
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Filename getter. |
|
107
|
|
|
* |
|
108
|
|
|
* @return string |
|
109
|
|
|
*/ |
|
110
|
1 |
|
public function getFilename() : string |
|
111
|
|
|
{ |
|
112
|
1 |
|
return $this->filename; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Bootstrap setter. |
|
117
|
|
|
* |
|
118
|
|
|
* @param $file |
|
119
|
|
|
*/ |
|
120
|
27 |
|
public function setBootstrap(string $file) |
|
121
|
|
|
{ |
|
122
|
27 |
|
$this->bootstrap = $file; |
|
123
|
27 |
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Bootstrap getter. |
|
127
|
|
|
* |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
4 |
|
public function getBootstrap() : string |
|
131
|
|
|
{ |
|
132
|
4 |
|
return $this->bootstrap; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Limit setter. |
|
137
|
|
|
* |
|
138
|
|
|
* @param array $limit |
|
139
|
|
|
*/ |
|
140
|
1 |
|
public function setLimit(array $limit) |
|
141
|
|
|
{ |
|
142
|
1 |
|
$this->limit = $limit; |
|
143
|
1 |
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Verbose setter. |
|
147
|
|
|
* |
|
148
|
|
|
* @param bool $bool |
|
149
|
|
|
*/ |
|
150
|
33 |
|
public function setVerbose(bool $bool) |
|
151
|
|
|
{ |
|
152
|
33 |
|
$this->verbose = $bool; |
|
153
|
33 |
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Verbose getter. |
|
157
|
|
|
* |
|
158
|
|
|
* @return bool |
|
159
|
|
|
*/ |
|
160
|
3 |
|
public function getVerbose() : bool |
|
161
|
|
|
{ |
|
162
|
3 |
|
return $this->verbose; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Colors setter. |
|
167
|
|
|
* |
|
168
|
|
|
* @param bool $bool |
|
169
|
|
|
*/ |
|
170
|
26 |
|
public function setColors(bool $bool) |
|
171
|
|
|
{ |
|
172
|
26 |
|
$this->colors = $bool; |
|
173
|
26 |
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Colors getter. |
|
177
|
|
|
* |
|
178
|
|
|
* @return bool |
|
179
|
|
|
*/ |
|
180
|
3 |
|
public function getColors() : bool |
|
181
|
|
|
{ |
|
182
|
3 |
|
return $this->colors; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Debug setter. |
|
187
|
|
|
* |
|
188
|
|
|
* @param bool $bool |
|
189
|
|
|
*/ |
|
190
|
2 |
|
public function setDebug(bool $bool) |
|
191
|
|
|
{ |
|
192
|
2 |
|
$this->debug = $bool; |
|
193
|
2 |
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Debug getter. |
|
197
|
|
|
* |
|
198
|
|
|
* @return bool |
|
199
|
|
|
*/ |
|
200
|
2 |
|
public function getDebug() : bool |
|
201
|
|
|
{ |
|
202
|
2 |
|
return $this->debug; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Simulate setter. |
|
207
|
|
|
* |
|
208
|
|
|
* @param bool $bool |
|
209
|
|
|
*/ |
|
210
|
1 |
|
public function setSimulate(bool $bool) |
|
211
|
|
|
{ |
|
212
|
1 |
|
$this->simulate = $bool; |
|
213
|
1 |
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Simulate getter. |
|
217
|
|
|
* |
|
218
|
|
|
* @return bool |
|
219
|
|
|
*/ |
|
220
|
1 |
|
public function isSimulation() : bool |
|
221
|
|
|
{ |
|
222
|
1 |
|
return $this->simulate; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Restore setter. |
|
227
|
|
|
* |
|
228
|
|
|
* @param bool $bool |
|
229
|
|
|
*/ |
|
230
|
1 |
|
public function setRestore(bool $bool) |
|
231
|
|
|
{ |
|
232
|
1 |
|
$this->restore = $bool; |
|
233
|
1 |
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Restore getter. |
|
237
|
|
|
* |
|
238
|
|
|
* @return bool |
|
239
|
|
|
*/ |
|
240
|
1 |
|
public function isRestore() : bool |
|
241
|
|
|
{ |
|
242
|
1 |
|
return $this->restore; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* Add a logger. |
|
247
|
|
|
* This accepts valid logger configs as well as valid Listener objects. |
|
248
|
|
|
* |
|
249
|
|
|
* @param mixed $logger |
|
250
|
|
|
* @throws \phpbu\App\Exception |
|
251
|
|
|
*/ |
|
252
|
28 |
|
public function addLogger($logger) |
|
253
|
|
|
{ |
|
254
|
28 |
|
if (!($logger instanceof Listener) && !($logger instanceof Configuration\Logger)) { |
|
255
|
1 |
|
throw new Exception('invalid logger, only \'Listener\' and valid logger configurations are accepted'); |
|
256
|
|
|
} |
|
257
|
27 |
|
$this->loggers[] = $logger; |
|
258
|
27 |
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* Get the list of logger configurations. |
|
262
|
|
|
* |
|
263
|
|
|
* @return array |
|
264
|
|
|
*/ |
|
265
|
6 |
|
public function getLoggers() : array |
|
266
|
|
|
{ |
|
267
|
6 |
|
return $this->loggers; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* Add a Backup configuration. |
|
272
|
|
|
* |
|
273
|
|
|
* @param \phpbu\App\Configuration\Backup $backup |
|
274
|
|
|
*/ |
|
275
|
14 |
|
public function addBackup(Configuration\Backup $backup) |
|
276
|
|
|
{ |
|
277
|
14 |
|
$this->backups[] = $backup; |
|
278
|
14 |
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* Get the list of backup configurations. |
|
282
|
|
|
* |
|
283
|
|
|
* @return \phpbu\App\Configuration\Backup[] |
|
284
|
|
|
*/ |
|
285
|
8 |
|
public function getBackups() : array |
|
286
|
|
|
{ |
|
287
|
8 |
|
return $this->backups; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Is given backup active. |
|
292
|
|
|
* Backups could be skipped by using the --limit option. |
|
293
|
|
|
* |
|
294
|
|
|
* @param string $backupName |
|
295
|
|
|
* @return bool |
|
296
|
|
|
*/ |
|
297
|
1 |
|
public function isBackupActive($backupName) : bool |
|
298
|
|
|
{ |
|
299
|
1 |
|
if (empty($this->limit) || in_array($backupName, $this->limit)) { |
|
300
|
1 |
|
return true; |
|
301
|
|
|
} |
|
302
|
1 |
|
return false; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* Working directory setter. |
|
307
|
|
|
* |
|
308
|
|
|
* @param string $wd |
|
309
|
|
|
*/ |
|
310
|
49 |
|
public static function setWorkingDirectory(string $wd) |
|
311
|
|
|
{ |
|
312
|
49 |
|
self::$workingDirectory = $wd; |
|
313
|
49 |
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* Working directory getter. |
|
317
|
|
|
* |
|
318
|
|
|
* @return string |
|
319
|
|
|
*/ |
|
320
|
16 |
|
public static function getWorkingDirectory() : string |
|
321
|
|
|
{ |
|
322
|
16 |
|
return !empty(self::$workingDirectory) ? self::$workingDirectory : getcwd(); |
|
323
|
|
|
} |
|
324
|
|
|
} |
|
325
|
|
|
|