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