1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the ekino Drupal Debug project. |
7
|
|
|
* |
8
|
|
|
* (c) ekino |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ekino\Drupal\Debug\Configuration\Model; |
15
|
|
|
|
16
|
|
|
use Monolog\Handler\StreamHandler; |
17
|
|
|
use Monolog\Logger; |
18
|
|
|
|
19
|
|
|
class DefaultsConfiguration extends AbstractConfiguration |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var false|Logger|null |
23
|
|
|
*/ |
24
|
|
|
private $logger; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
2 |
|
public function __construct(array $processedConfiguration) |
30
|
|
|
{ |
31
|
2 |
|
parent::__construct($processedConfiguration); |
32
|
|
|
|
33
|
2 |
|
$this->logger = false; |
34
|
2 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
2 |
|
public function getCacheDirectory(): string |
40
|
|
|
{ |
41
|
2 |
|
return $this->processedConfiguration['cache_directory']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return Logger|null |
46
|
|
|
*/ |
47
|
2 |
|
public function getLogger(): ?Logger |
48
|
|
|
{ |
49
|
2 |
|
if (false === $this->logger) { |
50
|
2 |
|
$loggerProcessedConfiguration = $this->processedConfiguration['logger']; |
51
|
|
|
|
52
|
2 |
|
$this->logger = $loggerProcessedConfiguration['enabled'] ? new Logger($loggerProcessedConfiguration['channel'], array( |
53
|
2 |
|
new StreamHandler($loggerProcessedConfiguration['file_path']), |
54
|
|
|
)) : null; |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
return $this->logger; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string|null |
62
|
|
|
*/ |
63
|
2 |
|
public function getCharset(): ?string |
64
|
|
|
{ |
65
|
2 |
|
return $this->processedConfiguration['charset']; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string|null |
70
|
|
|
*/ |
71
|
2 |
|
public function getFileLinkFormat(): ?string |
72
|
|
|
{ |
73
|
2 |
|
return $this->processedConfiguration['file_link_format']; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
2 |
|
public function serialize(): ?string |
80
|
|
|
{ |
81
|
2 |
|
return \serialize(array( |
82
|
2 |
|
$this->processedConfiguration, |
83
|
2 |
|
null === $this->logger ? null : false, |
84
|
|
|
)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
|
|
public function unserialize($serialized): void |
91
|
|
|
{ |
92
|
|
|
list($this->processedConfiguration, $this->logger) = \unserialize($serialized); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|