Completed
Push — master ( 0c38e0...116503 )
by Sebastian
03:25
created

Configuration::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

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