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
|
11 |
|
public function __construct(array $to, array $cc = [], array $bcc = []) |
31
|
|
|
{ |
32
|
11 |
|
$this->to = self::toStringArray($to); |
33
|
11 |
|
$this->cc = self::toStringArray($cc); |
34
|
11 |
|
$this->bcc = self::toStringArray($bcc); |
35
|
11 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return EmailAddress[] |
39
|
|
|
*/ |
40
|
3 |
|
public function to(): array |
41
|
|
|
{ |
42
|
3 |
|
return self::toObjectArray($this->to); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return EmailAddress[] |
47
|
|
|
*/ |
48
|
3 |
|
public function cc(): array |
49
|
|
|
{ |
50
|
3 |
|
return self::toObjectArray($this->cc); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return EmailAddress[] |
55
|
|
|
*/ |
56
|
3 |
|
public function bcc(): array |
57
|
|
|
{ |
58
|
3 |
|
return self::toObjectArray($this->bcc); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param EmailAddress[] $emailAddresses |
63
|
|
|
* @return string[[ |
|
|
|
|
64
|
|
|
*/ |
65
|
11 |
|
private static function toStringArray(array $emailAddresses) |
66
|
|
|
{ |
67
|
|
|
return array_map(function (EmailAddress $emailAddress) { |
68
|
11 |
|
return $emailAddress->emailAddress(); |
69
|
11 |
|
}, $emailAddresses); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string[] $emailAddresses |
74
|
|
|
* @return EmailAddress[] |
75
|
|
|
*/ |
76
|
6 |
|
private static function toObjectArray(array $emailAddresses): array |
77
|
|
|
{ |
78
|
|
|
return array_map(function (string $emailAddress) { |
79
|
6 |
|
return new EmailAddress($emailAddress); |
80
|
6 |
|
}, $emailAddresses); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
4 |
|
public function jsonRepresentation(): string |
87
|
|
|
{ |
88
|
4 |
|
return json_encode([ |
89
|
4 |
|
'to' => $this->to, |
90
|
4 |
|
'cc' => $this->cc, |
91
|
4 |
|
'bcc' => $this->bcc, |
92
|
|
|
]); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
4 |
|
public static function fromJsonRepresentation(string $jsonRepresentation): Destination |
99
|
|
|
{ |
100
|
4 |
|
$decoded = json_decode($jsonRepresentation, true); |
101
|
|
|
|
102
|
4 |
|
return new EmailDestination( |
103
|
4 |
|
self::toObjectArray($decoded['to']), |
104
|
4 |
|
self::toObjectArray($decoded['cc']), |
105
|
4 |
|
self::toObjectArray($decoded['bcc']) |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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.