1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpLightning\Config; |
6
|
|
|
|
7
|
|
|
use JsonSerializable; |
8
|
|
|
use PhpLightning\Config\Backend\BackendConfigInterface; |
9
|
|
|
|
10
|
|
|
final class LightningConfig implements JsonSerializable |
11
|
|
|
{ |
12
|
|
|
private ?string $domain = null; |
13
|
|
|
private ?string $receiver = null; |
14
|
|
|
private ?int $minSendable = null; |
15
|
|
|
private ?int $maxSendable = null; |
16
|
|
|
private BackendsConfig $backends; |
17
|
|
|
|
18
|
|
|
public function __construct() |
19
|
|
|
{ |
20
|
|
|
$this->backends = new BackendsConfig(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function setDomain(string $domain): self |
24
|
|
|
{ |
25
|
|
|
$this->domain = $domain; |
26
|
|
|
return $this; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function setReceiver(string $receiver): self |
30
|
|
|
{ |
31
|
|
|
$this->receiver = $receiver; |
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function setMinSendable(int $minSendable): self |
36
|
|
|
{ |
37
|
|
|
$this->minSendable = $minSendable; |
38
|
|
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function setMaxSendable(int $maxSendable): self |
42
|
|
|
{ |
43
|
|
|
$this->maxSendable = $maxSendable; |
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function addBackend(BackendConfigInterface $backendConfig): self |
48
|
|
|
{ |
49
|
|
|
$this->backends->add($backendConfig); |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function jsonSerialize(): array |
54
|
|
|
{ |
55
|
|
|
$result = [ |
56
|
|
|
'backends' => $this->backends->jsonSerialize(), |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
if ($this->domain !== null) { |
60
|
|
|
$result['domain'] = $this->domain; |
61
|
|
|
} |
62
|
|
|
if ($this->receiver !== null) { |
63
|
|
|
$result['receiver'] = $this->receiver; |
64
|
|
|
} |
65
|
|
|
if ($this->minSendable !== null) { |
66
|
|
|
$result['min-sendable'] = $this->minSendable; |
67
|
|
|
} |
68
|
|
|
if ($this->maxSendable !== null) { |
69
|
|
|
$result['max-sendable'] = $this->maxSendable; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $result; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|