|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Shippinno\Notification\Domain\Model; |
|
5
|
|
|
|
|
6
|
|
|
use Tanigami\ValueObjects\Web\EmailAddress; |
|
7
|
|
|
|
|
8
|
|
|
class EmailDestination extends Destination |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var string[] |
|
12
|
|
|
*/ |
|
13
|
|
|
private $to; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string[] |
|
17
|
|
|
*/ |
|
18
|
|
|
private $cc; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string[] |
|
22
|
|
|
*/ |
|
23
|
|
|
private $bcc; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param EmailAddress[] $to |
|
27
|
|
|
* @param EmailAddress[] $cc |
|
28
|
|
|
* @param EmailAddress[] $bcc |
|
29
|
|
|
*/ |
|
30
|
7 |
|
public function __construct(array $to, array $cc = [], array $bcc = []) |
|
31
|
|
|
{ |
|
32
|
7 |
|
$this->to = self::toStringArray($to); |
|
33
|
7 |
|
$this->cc = self::toStringArray($cc); |
|
34
|
7 |
|
$this->bcc = self::toStringArray($bcc); |
|
35
|
7 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return EmailAddress[] |
|
39
|
|
|
*/ |
|
40
|
2 |
|
public function to(): array |
|
41
|
|
|
{ |
|
42
|
2 |
|
return self::toObjectArray($this->to); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return EmailAddress[] |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function cc(): array |
|
49
|
|
|
{ |
|
50
|
2 |
|
return self::toObjectArray($this->cc); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return EmailAddress[] |
|
55
|
|
|
*/ |
|
56
|
2 |
|
public function bcc(): array |
|
57
|
|
|
{ |
|
58
|
2 |
|
return self::toObjectArray($this->bcc); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param EmailAddress[] $emailAddresses |
|
63
|
|
|
* @return string[[ |
|
|
|
|
|
|
64
|
|
|
*/ |
|
65
|
7 |
|
private static function toStringArray(array $emailAddresses) |
|
66
|
|
|
{ |
|
67
|
|
|
return array_map(function (EmailAddress $emailAddress) { |
|
68
|
7 |
|
return $emailAddress->emailAddress(); |
|
69
|
7 |
|
}, $emailAddresses); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string[] $emailAddresses |
|
74
|
|
|
* @return EmailAddress[] |
|
75
|
|
|
*/ |
|
76
|
2 |
|
private static function toObjectArray(array $emailAddresses): array |
|
77
|
|
|
{ |
|
78
|
|
|
return array_map(function (string $emailAddress) { |
|
79
|
2 |
|
return new EmailAddress($emailAddress); |
|
80
|
2 |
|
}, $emailAddresses); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritdoc} |
|
85
|
|
|
*/ |
|
86
|
3 |
|
public function destinationType(): string |
|
87
|
|
|
{ |
|
88
|
3 |
|
return get_class($this); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function jsonRepresentation(): string |
|
95
|
|
|
{ |
|
96
|
|
|
return json_encode([ |
|
97
|
|
|
'to' => $this->to, |
|
98
|
|
|
'cc' => $this->cc, |
|
99
|
|
|
'bcc' => $this->bcc, |
|
100
|
|
|
]); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* {@inheritdoc} |
|
105
|
|
|
*/ |
|
106
|
|
|
public static function fromJsonRepresentation(string $jsonRepresentation): Destination |
|
107
|
|
|
{ |
|
108
|
|
|
$decoded = json_decode($jsonRepresentation, true); |
|
109
|
|
|
|
|
110
|
|
|
return new EmailDestination( |
|
111
|
|
|
self::toObjectArray($decoded['to']), |
|
112
|
|
|
self::toObjectArray($decoded['cc']), |
|
113
|
|
|
self::toObjectArray($decoded['bcc']) |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.