1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace FH\Bundle\MailerBundle\Email; |
5
|
|
|
|
6
|
|
|
use Symfony\Component\Mime\Address; |
7
|
|
|
|
8
|
|
|
final class Participants |
9
|
|
|
{ |
10
|
|
|
private $sender; |
11
|
|
|
private $from; |
12
|
|
|
private $replyTo; |
13
|
|
|
private $to; |
14
|
|
|
private $cc; |
15
|
|
|
private $bcc; |
16
|
|
|
|
17
|
1 |
|
public static function fromArray(array $participants): self |
18
|
|
|
{ |
19
|
|
|
$createAddress = static function (array $address) { |
20
|
1 |
|
return self::createAddress($address); |
21
|
1 |
|
}; |
22
|
|
|
|
23
|
1 |
|
return new self( |
24
|
1 |
|
isset($participants['sender']) && is_array($participants['sender']) ? self::createAddress($participants['sender']) : null, |
25
|
1 |
|
array_map($createAddress, $participants['from'] ?? []), |
26
|
1 |
|
array_map($createAddress, $participants['reply_to'] ?? []), |
27
|
1 |
|
array_map($createAddress, $participants['to'] ?? []), |
28
|
1 |
|
array_map($createAddress, $participants['cc'] ?? []), |
29
|
1 |
|
array_map($createAddress, $participants['bcc'] ?? []) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
public function __construct( |
34
|
|
|
Address $sender = null, |
35
|
|
|
array $from = [], |
36
|
|
|
array $replyTo = [], |
37
|
|
|
array $to = [], |
38
|
|
|
array $cc = [], |
39
|
|
|
array $bcc = [] |
40
|
|
|
) { |
41
|
1 |
|
$this->sender = $sender; |
42
|
1 |
|
$this->from = $from; |
43
|
1 |
|
$this->replyTo = $replyTo; |
44
|
1 |
|
$this->to = $to; |
45
|
1 |
|
$this->cc = $cc; |
46
|
1 |
|
$this->bcc = $bcc; |
47
|
1 |
|
} |
48
|
|
|
|
49
|
1 |
|
public function getSender(): ?Address |
50
|
|
|
{ |
51
|
1 |
|
return $this->sender; |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
public function hasSender(): bool |
55
|
|
|
{ |
56
|
1 |
|
return $this->sender instanceof Address; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return Address[] |
61
|
|
|
*/ |
62
|
1 |
|
public function getFrom(): array |
63
|
|
|
{ |
64
|
1 |
|
return $this->from; |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
public function hasFrom(): bool |
68
|
|
|
{ |
69
|
1 |
|
return !empty($this->from); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return Address[] |
74
|
|
|
*/ |
75
|
1 |
|
public function getReplyTo(): array |
76
|
|
|
{ |
77
|
1 |
|
return $this->replyTo; |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
public function hasReplyTo(): bool |
81
|
|
|
{ |
82
|
1 |
|
return !empty($this->replyTo); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return Address[] |
87
|
|
|
*/ |
88
|
1 |
|
public function getTo(): array |
89
|
|
|
{ |
90
|
1 |
|
return $this->to; |
91
|
|
|
} |
92
|
|
|
|
93
|
1 |
|
public function hasTo(): bool |
94
|
|
|
{ |
95
|
1 |
|
return !empty($this->to); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return Address[] |
100
|
|
|
*/ |
101
|
1 |
|
public function getCc(): array |
102
|
|
|
{ |
103
|
1 |
|
return $this->cc; |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
public function hasCc(): bool |
107
|
|
|
{ |
108
|
1 |
|
return !empty($this->cc); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return Address[] |
113
|
|
|
*/ |
114
|
1 |
|
public function getBcc(): array |
115
|
|
|
{ |
116
|
1 |
|
return $this->bcc; |
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
public function hasBcc(): bool |
120
|
|
|
{ |
121
|
1 |
|
return !empty($this->bcc); |
122
|
|
|
} |
123
|
|
|
|
124
|
1 |
|
private static function createAddress(array $address): Address |
125
|
|
|
{ |
126
|
1 |
|
return new Address($address['address'], $address['name'] ?? ''); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|