1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is a part of the Yoqut package. |
5
|
|
|
* |
6
|
|
|
* (c) Sukhrob Khakimov <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that is distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Yoqut\Component\Sms\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The default SMS implementation |
16
|
|
|
* |
17
|
|
|
* @author Sukhrob Khakimov <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Sms implements SmsInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* The SMS is sent to an operator |
23
|
|
|
* |
24
|
|
|
* @var integer |
25
|
|
|
*/ |
26
|
|
|
const STATE_SENT = 0; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The SMS is accepted by an operator |
30
|
|
|
* |
31
|
|
|
* @var integer |
32
|
|
|
*/ |
33
|
|
|
const STATE_ACCEPTED = 1; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The SMS is rejected by an operator |
37
|
|
|
* |
38
|
|
|
* @var integer |
39
|
|
|
*/ |
40
|
|
|
const STATE_REJECTED = 2; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The SMS is delivered to a recipient |
44
|
|
|
* |
45
|
|
|
* @var integer |
46
|
|
|
*/ |
47
|
|
|
const STATE_DELIVERED = 3; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The SMS is not delivered to a recipient |
51
|
|
|
* |
52
|
|
|
* @var integer |
53
|
|
|
*/ |
54
|
|
|
const STATE_FAILED = 4; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The unique id of an SMS |
58
|
|
|
* |
59
|
|
|
* @var mixed |
60
|
|
|
*/ |
61
|
|
|
protected $id; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The sender of an SMS |
65
|
|
|
* |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
protected $sender; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The recipient of an SMS |
72
|
|
|
* |
73
|
|
|
* @var string |
74
|
|
|
*/ |
75
|
|
|
protected $recipient; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* The message of an SMS |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
protected $message; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* The state of an SMS |
86
|
|
|
* |
87
|
|
|
* @var integer |
88
|
|
|
*/ |
89
|
|
|
protected $state; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* The created date of an SMS |
93
|
|
|
* |
94
|
|
|
* @var \DateTime |
95
|
|
|
*/ |
96
|
|
|
protected $createdAt; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* The updated date of an SMS |
100
|
|
|
* |
101
|
|
|
* @var \DateTime |
102
|
|
|
*/ |
103
|
|
|
protected $updatedAt; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Constructor |
107
|
|
|
*/ |
108
|
|
|
public function __construct() |
109
|
|
|
{ |
110
|
|
|
$this->createdAt = new \DateTime(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Gets the id |
115
|
|
|
* |
116
|
|
|
* @return mixed |
117
|
|
|
*/ |
118
|
|
|
public function getId() |
119
|
|
|
{ |
120
|
|
|
return $this->id; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* {@inheritDoc} |
125
|
|
|
*/ |
126
|
|
|
public function setSender($sender) |
127
|
|
|
{ |
128
|
|
|
$this->sender = $sender; |
129
|
|
|
|
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* {@inheritDoc} |
135
|
|
|
*/ |
136
|
|
|
public function getSender() |
137
|
|
|
{ |
138
|
|
|
return $this->sender; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* {@inheritDoc} |
143
|
|
|
*/ |
144
|
|
|
public function setRecipient($recipient) |
145
|
|
|
{ |
146
|
|
|
$this->recipient = $recipient; |
147
|
|
|
|
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* {@inheritDoc} |
153
|
|
|
*/ |
154
|
|
|
public function getRecipient() |
155
|
|
|
{ |
156
|
|
|
return $this->recipient; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* {@inheritDoc} |
161
|
|
|
*/ |
162
|
|
|
public function setMessage($message) |
163
|
|
|
{ |
164
|
|
|
$this->message = $message; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* {@inheritDoc} |
171
|
|
|
*/ |
172
|
|
|
public function getMessage() |
173
|
|
|
{ |
174
|
|
|
return $this->message; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* {@inheritDoc} |
179
|
|
|
*/ |
180
|
|
|
public function setState($state) |
181
|
|
|
{ |
182
|
|
|
if (!in_array($state, self::getStates())) { |
183
|
|
|
throw new \InvalidArgumentException(); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
$this->state = $state; |
187
|
|
|
|
188
|
|
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* {@inheritDoc} |
193
|
|
|
*/ |
194
|
|
|
public function getState() |
195
|
|
|
{ |
196
|
|
|
return $this->state; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* {@inheritDoc} |
201
|
|
|
*/ |
202
|
|
|
public function setCreatedAt(\DateTime $createdAt) |
203
|
|
|
{ |
204
|
|
|
$this->createdAt = $createdAt; |
205
|
|
|
|
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* {@inheritDoc} |
211
|
|
|
*/ |
212
|
|
|
public function getCreatedAt() |
213
|
|
|
{ |
214
|
|
|
return $this->createdAt; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* {@inheritDoc} |
219
|
|
|
*/ |
220
|
|
|
public function setUpdatedAt(\DateTime $updatedAt) |
221
|
|
|
{ |
222
|
|
|
$this->updatedAt = $updatedAt; |
223
|
|
|
|
224
|
|
|
return $this; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* {@inheritDoc} |
229
|
|
|
*/ |
230
|
|
|
public function getUpdatedAt() |
231
|
|
|
{ |
232
|
|
|
return $this->updatedAt; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Gets all the states |
237
|
|
|
* |
238
|
|
|
* @return array |
239
|
|
|
*/ |
240
|
|
|
public static function getStates() |
241
|
|
|
{ |
242
|
|
|
return array( |
243
|
|
|
self::STATE_SENT, |
244
|
|
|
self::STATE_ACCEPTED, |
245
|
|
|
self::STATE_REJECTED, |
246
|
|
|
self::STATE_DELIVERED, |
247
|
|
|
self::STATE_FAILED, |
248
|
|
|
); |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|