Completed
Push — master ( 5c49fa...3fbda1 )
by Sebastian
07:27
created

Configuration::getBackups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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
     * List of include paths
61
     *
62
     * @var array
63
     */
64
    private $includePaths = [];
65
66
    /**
67
     * List of ini settings
68
     *
69
     * @var array
70
     */
71
    private $iniSettings = [];
72
73
    /**
74
     * List of logger configurations
75
     *
76
     * @var array
77
     */
78
    private $loggers = [];
79
80
    /**
81
     * List of backup configurations
82
     *
83
     * @var array
84
     */
85
    private $backups = [];
86
87
    /**
88
     * List of backus to execute
89
     *
90
     * @var array
91
     */
92 33
    private $limit = [];
93
94 33
    /**
95 33
     * Working directory
96
     *
97
     * @var string
98
     */
99
    private static $workingDirectory;
100
101
    /**
102 24
     * Filename setter.
103
     *
104 24
     * @param string $file
105 24
     */
106 24
    public function setFilename($file)
107
    {
108
        $this->filename = $file;
109
        self::setWorkingDirectory(dirname($file));
110
    }
111
112
    /**
113 1
     * Filename getter.
114
     *
115 1
     * @return string
116
     */
117
    public function getFilename()
118
    {
119
        return $this->filename;
120
    }
121
122
    /**
123 1
     * Bootstrap setter.
124
     *
125 1
     * @param $file
126 1
     */
127
    public function setBootstrap($file)
128
    {
129
        $this->bootstrap = $file;
130
    }
131
132
    /**
133 2
     * Bootstrap getter.
134
     *
135 2
     * @return string
136
     */
137
    public function getBootstrap()
138
    {
139
        return $this->bootstrap;
140
    }
141
142
    /**
143 14
     * Limit setter.
144
     *
145 14
     * @param array $limit
146 14
     */
147
    public function setLimit(array $limit)
148
    {
149
        $this->limit = $limit;
150
    }
151
152
    /**
153 2
     * Verbose setter.
154
     *
155 2
     * @param bool $bool
156
     */
157
    public function setVerbose($bool)
158
    {
159
        $this->verbose = $bool;
160
    }
161
162
    /**
163 14
     * Verbose getter.
164
     *
165 14
     * @return bool
166 14
     */
167
    public function getVerbose()
168
    {
169
        return $this->verbose;
170
    }
171
172
    /**
173 2
     * Colors setter.
174
     *
175 2
     * @param bool $bool
176
     */
177
    public function setColors($bool)
178
    {
179
        $this->colors = $bool;
180
    }
181
182
    /**
183 14
     * Colors getter.
184
     *
185 14
     * @return bool
186 14
     */
187
    public function getColors()
188
    {
189
        return $this->colors;
190
    }
191
192
    /**
193 2
     * Debug setter.
194
     *
195 2
     * @param bool $bool
196
     */
197
    public function setDebug($bool)
198
    {
199
        $this->debug = $bool;
200
    }
201
202
    /**
203 2
     * Debug getter.
204
     *
205 2
     * @return bool
206 2
     */
207
    public function getDebug()
208
    {
209
        return $this->debug;
210
    }
211
212
    /**
213 2
     * Simulate setter.
214
     *
215 2
     * @param bool $bool
216
     */
217
    public function setSimulate($bool)
218
    {
219
        $this->simulate = $bool;
220
    }
221
222
    /**
223 12
     * Simulate getter.
224
     *
225 12
     * @return bool
226 12
     */
227
    public function isSimulation()
228
    {
229
        return $this->simulate;
230
    }
231
232
    /**
233 3
     * Add an include_path.
234
     *
235 3
     * @param string $path
236
     */
237
    public function addIncludePath($path)
238
    {
239
        $this->includePaths[] = $path;
240
    }
241
242
    /**
243
     * Get the list of include path.
244 12
     *
245
     * @return array
246 12
     */
247 12
    public function getIncludePaths()
248
    {
249
        return $this->includePaths;
250
    }
251
252
    /**
253
     * Add a ini settings.
254 3
     *
255
     * @param string $name
256 3
     * @param string $value
257
     */
258
    public function addIniSetting($name, $value)
259
    {
260
        $this->iniSettings[$name] = $value;
261
    }
262
263
    /**
264
     * Get the list of ini settings.
265
     *
266 13
     * @return array
267
     */
268 13
    public function getIniSettings()
269 1
    {
270
        return $this->iniSettings;
271 12
    }
272 12
273
    /**
274
     * Add a logger.
275
     * This accepts valid logger configs as well as valid Listener objects.
276
     *
277
     * @param  mixed $logger
278
     * @throws \phpbu\App\Exception
279 4
     */
280
    public function addLogger($logger)
281 4
    {
282
        if (!($logger instanceof Listener) && !($logger instanceof Configuration\Logger)) {
283
            throw new Exception('invalid logger, only \'Listener\' and valid logger configurations are accepted');
284
        }
285
        $this->loggers[] = $logger;
286
    }
287
288
    /**
289 7
     * Get the list of logger configurations.
290
     *
291 7
     * @return array
292 7
     */
293
    public function getLoggers()
294
    {
295
        return $this->loggers;
296
    }
297
298
    /**
299 3
     * Add a Backup configuration.
300
     *
301 3
     * @param \phpbu\App\Configuration\Backup $backup
302
     */
303
    public function addBackup(Configuration\Backup $backup)
304
    {
305
        $this->backups[] = $backup;
306
    }
307
308
    /**
309
     * Get the list of backup configurations.
310
     *
311
     * @return array
312
     */
313
    public function getBackups()
314
    {
315
        return $this->backups;
316
    }
317
318
    /**
319
     * Is given backup active.
320
     * Backups could be skipped by using the --limit option.
321
     *
322
     * @param  string $backupName
323
     * @return bool
324
     */
325
    public function isBackupActive($backupName)
326
    {
327
        if (empty($this->limit) || in_array($backupName, $this->limit)) {
328
            return true;
329
        }
330
        return false;
331
    }
332
333
    /**
334
     * Working directory setter.
335
     *
336
     * @param string $wd
337
     */
338
    public static function setWorkingDirectory($wd)
339
    {
340
        self::$workingDirectory = $wd;
341
    }
342
343
    /**
344
     * Working directory getter.
345
     *
346
     * @return string
347
     */
348
    public static function getWorkingDirectory()
349
    {
350
        return !empty(self::$workingDirectory) ? self::$workingDirectory : getcwd();
351
    }
352
}
353