Completed
Push — master ( 5d3bf9...5839aa )
by Sebastian
03:18
created

Configuration::getIniSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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