Completed
Push — develop ( a29501...ca2e15 )
by Peter
01:18
created

DebuggerOptions::setFireLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Webino (http://webino.sk/)
4
 *
5
 * @link        https://github.com/webino/WebinoDebug/ for the canonical source repository
6
 * @copyright   Copyright (c) 2014-2018 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDebug\Options;
11
12
use WebinoDebug\Debugger;
13
use Zend\Stdlib\AbstractOptions;
14
use Zend\Stdlib\ArrayUtils;
15
16
/**
17
 * Class DebuggerOptions
18
 */
19
class DebuggerOptions extends AbstractOptions
20
{
21
    /**
22
     * @var bool
23
     */
24
    protected $enabled = true;
25
26
    /**
27
     * @var bool|null
28
     */
29
    protected $mode = null;
30
31
    /**
32
     * @var bool
33
     */
34
    protected $bar = false;
35
36
    /**
37
     * @var string
38
     */
39
    protected $barTitle;
40
41
    /**
42
     * @var array
43
     */
44
    protected $barInfo = [];
45
46
    /**
47
     * @var array
48
     */
49
    protected $barPanels = [
50
        'WebinoDebug:info'     => Debugger\InfoPanel::class,
51
        'WebinoDebug:timer'    => Debugger\TimerPanel::class,
52
        'WebinoDebug:config'   => Debugger\ConfigPanel::class,
53
        'WebinoDebug:services' => Debugger\ServicesPanel::class,
54
        'WebinoDebug:events'   => Debugger\EventPanel::class,
55
    ];
56
57
    /**
58
     * @var array
59
     */
60
    protected $cssFiles = [__DIR__ . '/../../../data/assets/Debugger/style.css'];
61
62
    /**
63
     * @var array
64
     */
65
    protected $jsFiles = [__DIR__ . '/../../../data/assets/Debugger/script.js'];
66
67
    /**
68
     * @var bool
69
     */
70
    protected $strict = false;
71
72
    /**
73
     * @var string|null
74
     */
75
    protected $log;
76
77
    /**
78
     * @var string
79
     */
80
    protected $email = '';
81
82
    /**
83
     * @var int
84
     */
85
    protected $maxDepth = 10;
86
87
    /**
88
     * @var int
89
     */
90
    protected $maxLength = 300;
91
92
    /**
93
     * @var bool
94
     */
95
    protected $barNoLogo = false;
96
97
    /**
98
     * @var bool
99
     */
100
    protected $barNoClose = false;
101
102
    /**
103
     * @var bool
104
     */
105
    protected $fireLogger = false;
106
107
    /**
108
     * Is debugger enabled?
109
     *
110
     * @return bool
111
     */
112
    public function isEnabled(): bool
113
    {
114
        return $this->enabled;
115
    }
116
117
    /**
118
     * Enable debugger
119
     *
120
     * @param bool $enabled
121
     * @return $this
122
     */
123
    public function setEnabled($enabled = true)
124
    {
125
        $this->enabled = (bool) $enabled;
126
        return $this;
127
    }
128
129
    /**
130
     * Is debugger disabled?
131
     *
132
     * @return bool
133
     */
134
    public function isDisabled(): bool
135
    {
136
        return !$this->enabled;
137
    }
138
139
    /**
140
     * Debugger mode
141
     *
142
     * true  = production|false
143
     * false = development|null
144
     * null  = autodetect|IP address(es) csv/array
145
     *
146
     * @return bool|null
147
     */
148
    public function getMode(): ?bool
149
    {
150
        return $this->mode;
151
    }
152
153
    /**
154
     * Debugger mode, production or development.
155
     *
156
     * @param bool|null $mode
157
     * @return $this
158
     */
159
    public function setMode($mode)
160
    {
161
        $this->mode = (null === $mode ? null : (bool) $mode);
162
        return $this;
163
    }
164
165
    /**
166
     * Is debugger bar enabled?
167
     *
168
     * @return bool
169
     */
170
    public function hasBar(): bool
171
    {
172
        return $this->bar;
173
    }
174
175
    /**
176
     * Toggle debugger bar
177
     *
178
     * @param bool $bar
179
     * @return $this
180
     */
181
    public function setBar($bar)
182
    {
183
        $this->bar = (bool) $bar;
184
        return $this;
185
    }
186
187
    /**
188
     * Debugger bar panels
189
     *
190
     * @return array
191
     */
192
    public function getBarPanels(): array
193
    {
194
        return $this->barPanels;
195
    }
196
197
    /**
198
     * Set custom debugger bar panels
199
     *
200
     * @param array $barPanels
201
     * @return $this
202
     */
203
    public function setBarPanels(array $barPanels)
204
    {
205
        $this->barPanels = ArrayUtils::merge($this->barPanels, $barPanels);
206
        return $this;
207
    }
208
209
    /**
210
     * @return array
211
     */
212
    public function getCssFiles(): array
213
    {
214
        return $this->cssFiles;
215
    }
216
217
    /**
218
     * Set custom CSS files
219
     *
220
     * @param array $cssFiles
221
     * @return $this
222
     */
223
    public function setCssFiles(array $cssFiles)
224
    {
225
        $this->cssFiles = ArrayUtils::merge($this->cssFiles, $cssFiles);
226
        return $this;
227
    }
228
229
    /**
230
     * @return array
231
     */
232
    public function getJsFiles(): array
233
    {
234
        return $this->jsFiles;
235
    }
236
237
    /**
238
     * Set custom Javascript files
239
     *
240
     * @param array $jsFiles
241
     * @return $this
242
     */
243
    public function setJsFiles(array $jsFiles)
244
    {
245
        $this->jsFiles = ArrayUtils::merge($this->jsFiles, $jsFiles);
246
        return $this;
247
    }
248
249
    /**
250
     * Return custom debugger bar info
251
     *
252
     * @return array
253
     */
254
    public function getBarInfo(): array
255
    {
256
        return $this->barInfo;
257
    }
258
259
    /**
260
     * Set custom debugger bar info
261
     *
262
     * @param array $barInfo
263
     * @return $this
264
     */
265
    public function setBarInfo(array $barInfo)
266
    {
267
        $this->barInfo = ArrayUtils::merge($this->barInfo, $barInfo);
268
        return $this;
269
    }
270
271
    /**
272
     * @return bool
273
     */
274
    public function isStrict(): bool
275
    {
276
        return $this->strict;
277
    }
278
279
    /**
280
     * Strict errors?
281
     *
282
     * @param bool $strict
283
     * @return $this
284
     */
285
    public function setStrict($strict)
286
    {
287
        $this->strict = (bool) $strict;
288
        return $this;
289
    }
290
291
    /**
292
     * @return string Empty string to disable, null for default
293
     */
294
    public function getLog(): string
295
    {
296
        if (null === $this->log) {
297
            $this->setLog('data/log');
298
        }
299
        return $this->log;
300
    }
301
302
    /**
303
     * Path to log directory
304
     *
305
     * @param string $log
306
     * @return $this
307
     */
308
    public function setLog($log)
309
    {
310
        $this->log = realpath($log);
311
        return $this;
312
    }
313
314
    /**
315
     * Administrator address
316
     *
317
     * @return string
318
     */
319
    public function getEmail(): string
320
    {
321
        return $this->email;
322
    }
323
324
    /**
325
     * Configure debugger administrator email
326
     *
327
     * @param string $email
328
     * @return $this
329
     */
330
    public function setEmail($email)
331
    {
332
        $this->email = (string) $email;
333
        return $this;
334
    }
335
336
    /**
337
     * @return int
338
     */
339
    public function getMaxDepth(): int
340
    {
341
        return $this->maxDepth;
342
    }
343
344
    /**
345
     * Variable dump max depth
346
     *
347
     * @param int $maxDepth
348
     * @return $this
349
     */
350
    public function setMaxDepth($maxDepth)
351
    {
352
        $this->maxDepth = (int) $maxDepth;
353
        return $this;
354
    }
355
356
    /**
357
     * @return int
358
     */
359
    public function getMaxLength(): int
360
    {
361
        return $this->maxLength;
362
    }
363
364
    /**
365
     * Maximum length of a variable
366
     *
367
     * @param int $maxLength
368
     * @return $this
369
     */
370
    public function setMaxLength($maxLength)
371
    {
372
        $this->maxLength = (int) $maxLength;
373
        return $this;
374
    }
375
376
    /**
377
     * Return debugger bar title
378
     *
379
     * @return string
380
     */
381
    public function getBarTitle(): string
382
    {
383
        return $this->barTitle;
384
    }
385
386
    /**
387
     * Set debugger bar custom title
388
     *
389
     * @param string $barTitle
390
     * @return $this
391
     */
392
    public function setBarTitle($barTitle)
393
    {
394
        $this->barTitle = (string) $barTitle;
395
        return $this;
396
    }
397
398
    /**
399
     * Has debugger bar a disabled logo?
400
     *
401
     * @return bool
402
     */
403
    public function hasBarNoLogo(): bool
404
    {
405
        return $this->barNoLogo;
406
    }
407
408
    /**
409
     * Set debugger bar logo disabled
410
     *
411
     * @param bool $barNoLogo
412
     * @return $this
413
     */
414
    public function setBarNoLogo($barNoLogo = true)
415
    {
416
        $this->barNoLogo = (bool) $barNoLogo;
417
        return $this;
418
    }
419
420
    /**
421
     * Has debugger bar close button disabled?
422
     *
423
     * @return bool
424
     */
425
    public function hasBarNoClose(): bool
426
    {
427
        return $this->barNoClose;
428
    }
429
430
    /**
431
     * Disable debugger bar close button
432
     *
433
     * @param bool $barNoClose
434
     * @return $this
435
     */
436
    public function setBarNoClose($barNoClose = true)
437
    {
438
        $this->barNoClose = (bool) $barNoClose;
439
        return $this;
440
    }
441
442
    /**
443
     * Is fire logger enabled?
444
     *
445
     * @return bool
446
     */
447
    public function hasFireLogger(): bool
448
    {
449
        return $this->fireLogger;
450
    }
451
452
    /**
453
     * Use fire logger
454
     *
455
     * @param bool $fireLogger
456
     * @return $this
457
     */
458
    public function setFireLogger($fireLogger = true)
459
    {
460
        $this->fireLogger = (bool) $fireLogger;
461
        return $this;
462
    }
463
}
464