|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fazland\SkebbyRestClient\DataStructure; |
|
4
|
|
|
use Fazland\SkebbyRestClient\Constant\ValidityPeriods; |
|
5
|
|
|
use Fazland\SkebbyRestClient\Exception\InvalidDeliveryStartException; |
|
6
|
|
|
use Fazland\SkebbyRestClient\Exception\InvalidValidityPeriodException; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @author Massimiliano Braglia <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class Sms |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var string[] |
|
15
|
|
|
*/ |
|
16
|
|
|
private $recipients; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string[][] |
|
20
|
|
|
*/ |
|
21
|
|
|
private $recipientVariables; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
private $text; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $userReference; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var \DateTime |
|
35
|
|
|
*/ |
|
36
|
|
|
private $deliveryStart; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var \DateInterval |
|
40
|
|
|
*/ |
|
41
|
|
|
private $validityPeriod; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Sms constructor. |
|
45
|
|
|
*/ |
|
46
|
10 |
|
public function __construct() |
|
47
|
|
|
{ |
|
48
|
10 |
|
$this->recipients = []; |
|
49
|
10 |
|
$this->recipientVariables = []; |
|
50
|
10 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return static |
|
54
|
|
|
*/ |
|
55
|
7 |
|
public static function create() |
|
56
|
|
|
{ |
|
57
|
7 |
|
return new static(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string[] |
|
62
|
|
|
*/ |
|
63
|
8 |
|
public function getRecipients() |
|
64
|
|
|
{ |
|
65
|
8 |
|
return $this->recipients; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param string[] $recipients |
|
70
|
|
|
* |
|
71
|
|
|
* @return $this |
|
72
|
|
|
*/ |
|
73
|
5 |
|
public function setRecipients(array $recipients) |
|
74
|
|
|
{ |
|
75
|
5 |
|
$this->recipients = $recipients; |
|
76
|
|
|
|
|
77
|
5 |
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param string $recipient |
|
82
|
|
|
* |
|
83
|
|
|
* @return $this |
|
84
|
|
|
*/ |
|
85
|
3 |
|
public function addRecipient($recipient) |
|
86
|
|
|
{ |
|
87
|
3 |
|
$this->recipients[] = $recipient; |
|
88
|
|
|
|
|
89
|
3 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param string $recipient |
|
94
|
|
|
* |
|
95
|
|
|
* @return $this |
|
96
|
|
|
*/ |
|
97
|
1 |
|
public function removeRecipient($recipient) |
|
98
|
|
|
{ |
|
99
|
1 |
|
$itemPosition = array_search($recipient, $this->recipients); |
|
100
|
|
|
|
|
101
|
1 |
|
if (false !== $itemPosition) { |
|
102
|
1 |
|
unset($this->recipients[$itemPosition]); |
|
103
|
1 |
|
} |
|
104
|
|
|
|
|
105
|
1 |
|
unset($this->recipientVariables[$recipient]); |
|
106
|
|
|
|
|
107
|
1 |
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return bool |
|
112
|
|
|
*/ |
|
113
|
7 |
|
public function hasRecipients() |
|
114
|
|
|
{ |
|
115
|
7 |
|
return ! empty($this->recipients); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return string[][] |
|
120
|
|
|
*/ |
|
121
|
4 |
|
public function getRecipientVariables() |
|
122
|
|
|
{ |
|
123
|
4 |
|
return $this->recipientVariables; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param string $recipient |
|
128
|
|
|
* @param string[] $recipientVariables |
|
129
|
|
|
* |
|
130
|
|
|
* @return $this |
|
131
|
|
|
*/ |
|
132
|
1 |
|
public function setRecipientVariables($recipient, array $recipientVariables) |
|
133
|
|
|
{ |
|
134
|
1 |
|
$this->recipientVariables[$recipient] = $recipientVariables; |
|
135
|
|
|
|
|
136
|
1 |
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param string $recipient |
|
141
|
|
|
* @param string $recipientVariable |
|
142
|
|
|
* @param string $recipientVariableValue |
|
143
|
|
|
* |
|
144
|
|
|
* @return $this |
|
145
|
|
|
*/ |
|
146
|
2 |
|
public function addRecipientVariable($recipient, $recipientVariable, $recipientVariableValue) |
|
147
|
|
|
{ |
|
148
|
2 |
|
if (! isset($this->recipientVariables[$recipient])) { |
|
149
|
2 |
|
$this->recipientVariables[$recipient] = []; |
|
150
|
2 |
|
} |
|
151
|
|
|
|
|
152
|
2 |
|
$this->recipientVariables[$recipient][$recipientVariable] = $recipientVariableValue; |
|
153
|
|
|
|
|
154
|
2 |
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @param string $recipient |
|
159
|
|
|
* @param string $recipientVariable |
|
160
|
|
|
* |
|
161
|
|
|
* @return $this |
|
162
|
|
|
*/ |
|
163
|
|
|
public function removeRecipientVariable($recipient, $recipientVariable) |
|
164
|
|
|
{ |
|
165
|
|
|
unset($this->recipientVariables[$recipient][$recipientVariable]); |
|
166
|
|
|
|
|
167
|
|
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return bool |
|
172
|
|
|
*/ |
|
173
|
6 |
|
public function hasRecipientVariables() |
|
174
|
|
|
{ |
|
175
|
6 |
|
return ! empty($this->recipientVariables); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @return $this |
|
180
|
|
|
*/ |
|
181
|
1 |
|
public function clearRecipientVariables() |
|
182
|
|
|
{ |
|
183
|
1 |
|
$this->recipientVariables = []; |
|
184
|
|
|
|
|
185
|
1 |
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @return string |
|
190
|
|
|
*/ |
|
191
|
6 |
|
public function getText() |
|
192
|
|
|
{ |
|
193
|
6 |
|
return $this->text; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @param string $text |
|
198
|
|
|
* |
|
199
|
|
|
* @return $this |
|
200
|
|
|
*/ |
|
201
|
7 |
|
public function setText($text) |
|
202
|
|
|
{ |
|
203
|
7 |
|
$this->text = $text; |
|
204
|
|
|
|
|
205
|
7 |
|
return $this; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @return string |
|
210
|
|
|
*/ |
|
211
|
6 |
|
public function getUserReference() |
|
212
|
|
|
{ |
|
213
|
6 |
|
return $this->userReference; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param string $userReference |
|
218
|
|
|
* |
|
219
|
|
|
* @return $this |
|
220
|
|
|
*/ |
|
221
|
1 |
|
public function setUserReference($userReference) |
|
222
|
|
|
{ |
|
223
|
1 |
|
$this->userReference = $userReference; |
|
224
|
|
|
|
|
225
|
1 |
|
return $this; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* @return \DateTime |
|
230
|
|
|
*/ |
|
231
|
6 |
|
public function getDeliveryStart() |
|
232
|
|
|
{ |
|
233
|
6 |
|
return $this->deliveryStart; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @param \DateTime|null $deliveryStart |
|
238
|
|
|
* |
|
239
|
|
|
* @return $this |
|
240
|
|
|
* |
|
241
|
|
|
* @throws InvalidDeliveryStartException |
|
242
|
|
|
*/ |
|
243
|
1 |
|
public function setDeliveryStart(\DateTime $deliveryStart = null) |
|
244
|
|
|
{ |
|
245
|
1 |
|
if (null !== $deliveryStart && $deliveryStart < new \DateTime()) { |
|
246
|
1 |
|
throw new InvalidDeliveryStartException(); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
$this->deliveryStart = $deliveryStart; |
|
250
|
|
|
|
|
251
|
|
|
return $this; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* @return \DateInterval |
|
256
|
|
|
*/ |
|
257
|
6 |
|
public function getValidityPeriod() |
|
258
|
|
|
{ |
|
259
|
6 |
|
return $this->validityPeriod; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* @param \DateInterval|null $validityPeriod |
|
264
|
|
|
* |
|
265
|
|
|
* @return $this |
|
266
|
|
|
* |
|
267
|
|
|
* @throws InvalidValidityPeriodException |
|
268
|
|
|
*/ |
|
269
|
1 |
|
public function setValidityPeriod(\DateInterval $validityPeriod = null) |
|
270
|
|
|
{ |
|
271
|
1 |
|
if (null !== $validityPeriod && |
|
272
|
1 |
|
($validityPeriod->i < ValidityPeriods::MIN || $validityPeriod->i > ValidityPeriods::MAX) |
|
273
|
1 |
|
) { |
|
274
|
1 |
|
throw new InvalidValidityPeriodException(); |
|
275
|
|
|
} |
|
276
|
|
|
$this->validityPeriod = $validityPeriod; |
|
277
|
|
|
|
|
278
|
|
|
return $this; |
|
279
|
|
|
} |
|
280
|
|
|
} |
|
281
|
|
|
|