-
Notifications
You must be signed in to change notification settings - Fork 0
/
Envelope.php
86 lines (74 loc) · 1.89 KB
/
Envelope.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
* This file is part of the Klipper package.
*
* (c) François Pluchino <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Klipper\Component\SmsSender;
use Klipper\Component\SmsSender\Exception\InvalidArgumentException;
use Klipper\Component\SmsSender\Mime\Phone;
/**
* Sms envelope.
*
* @author François Pluchino <[email protected]>
*/
class Envelope
{
private Phone $from;
/**
* @var Phone[]
*/
private array $recipients = [];
/**
* @param Phone $from The from phone
* @param Phone[] $recipients The recipient phones
*/
public function __construct(Phone $from, array $recipients)
{
$this->from = $from;
$this->setRecipients($recipients);
}
/**
* Set the from phone.
*
* @param Phone $from The from phone
*/
public function setFrom(Phone $from): void
{
$this->from = $from;
}
/**
* Get the from phone.
*/
public function getFrom(): Phone
{
return $this->from;
}
/**
* Set the recipient phones.
*
* @param array $recipients The recipient phones
*/
public function setRecipients(array $recipients): void
{
$this->recipients = [];
foreach ($recipients as $recipient) {
if (!$recipient instanceof Phone) {
throw new InvalidArgumentException(sprintf('A recipient must be an instance of "%s" (got "%s").', Phone::class, \is_object($recipient) ? \get_class($recipient) : \gettype($recipient)));
}
$this->recipients[] = $recipient;
}
}
/**
* Get the recipient phones.
*
* @return Phone[]
*/
public function getRecipients(): array
{
return $this->recipients;
}
}