1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the smsmode-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2019 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\SMSModeBundle\EventListener; |
13
|
|
|
|
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
use Symfony\Component\EventDispatcher\Event; |
16
|
|
|
use WBW\Bundle\SMSModeBundle\Event\AbstractSMSModeEvent; |
17
|
|
|
use WBW\Bundle\SMSModeBundle\Event\AddingContactEvent; |
18
|
|
|
use WBW\Bundle\SMSModeBundle\Event\CheckingSMSMessageStatusEvent; |
19
|
|
|
use WBW\Bundle\SMSModeBundle\Event\CreatingSubAccountEvent; |
20
|
|
|
use WBW\Bundle\SMSModeBundle\Event\DeletingSMSEvent; |
21
|
|
|
use WBW\Bundle\SMSModeBundle\Event\DeletingSubAccountEvent; |
22
|
|
|
use WBW\Bundle\SMSModeBundle\Event\DeliveryReportEvent; |
23
|
|
|
use WBW\Bundle\SMSModeBundle\Event\RetrievingSMSReplyEvent; |
24
|
|
|
use WBW\Bundle\SMSModeBundle\Event\SendingSMSBatchEvent; |
25
|
|
|
use WBW\Bundle\SMSModeBundle\Event\SendingSMSMessageEvent; |
26
|
|
|
use WBW\Bundle\SMSModeBundle\Event\SendingTextToSpeechSMSEvent; |
27
|
|
|
use WBW\Bundle\SMSModeBundle\Event\SendingUnicodeSMSEvent; |
28
|
|
|
use WBW\Bundle\SMSModeBundle\Event\SentSMSMessageListEvent; |
29
|
|
|
use WBW\Bundle\SMSModeBundle\Event\TransferringCreditsEvent; |
30
|
|
|
use WBW\Bundle\SMSModeBundle\Factory\SMSModeFactory; |
31
|
|
|
use WBW\Library\SMSMode\Exception\APIException; |
32
|
|
|
use WBW\Library\SMSMode\Model\AbstractRequest; |
33
|
|
|
use WBW\Library\SMSMode\Model\AbstractResponse; |
34
|
|
|
use WBW\Library\SMSMode\Model\Authentication; |
35
|
|
|
use WBW\Library\SMSMode\Provider\APIProvider; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* sMsmode event listener. |
39
|
|
|
* |
40
|
|
|
* @author webeweb <https://github.com/webeweb/> |
41
|
|
|
* @package WBW\Bundle\SMSModeBundle\EventListener |
42
|
|
|
*/ |
43
|
|
|
class SMSModeEventListener { |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Service name. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
const SERVICE_NAME = "webeweb.smsmode.event_listener"; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* API provider. |
54
|
|
|
* |
55
|
|
|
* @var APIProvider |
56
|
|
|
*/ |
57
|
|
|
private $apiProvider; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Constructor. |
61
|
|
|
*/ |
62
|
|
|
public function __construct() { |
63
|
|
|
$authentication = new Authentication(); |
64
|
|
|
$this->setApiProvider(new APIProvider($authentication)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Before return an event. |
69
|
|
|
* |
70
|
|
|
* @param AbstractSMSModeEvent $event The event. |
71
|
|
|
* @param AbstractRequest $request The request. |
72
|
|
|
* @param AbstractResponse $response The response. |
73
|
|
|
* @return Event Returns the event. |
74
|
|
|
*/ |
75
|
|
|
protected function beforeReturnEvent(AbstractSMSModeEvent $event, AbstractRequest $request, AbstractResponse $response) { |
76
|
|
|
|
77
|
|
|
$event->setRequest($request); |
78
|
|
|
$event->setResponse($response); |
79
|
|
|
|
80
|
|
|
return $event; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the API provider. |
85
|
|
|
* |
86
|
|
|
* @return APIProvider Returns the API provider. |
87
|
|
|
*/ |
88
|
|
|
public function getApiProvider() { |
89
|
|
|
return $this->apiProvider; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* On adding contact. |
94
|
|
|
* |
95
|
|
|
* @param AddingContactEvent $event The adding contact event. |
96
|
|
|
* @return AddingContactEvent Returns the adding contact event. |
97
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
98
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
99
|
|
|
*/ |
100
|
|
|
public function onAddingContact(AddingContactEvent $event) { |
101
|
|
|
|
102
|
|
|
$request = SMSModeFactory::newAddingContactRequest($event->getAddingContact()); |
103
|
|
|
$response = $this->getApiProvider()->addingContact($request); |
104
|
|
|
|
105
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* On checking SMS message status. |
110
|
|
|
* |
111
|
|
|
* @param CheckingSMSMessageStatusEvent $event The checking SMS message status event. |
112
|
|
|
* @return CheckingSMSMessageStatusEvent Returns the checking SMS message status event. |
113
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
114
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
115
|
|
|
*/ |
116
|
|
|
public function onCheckingSMSMessageStatus(CheckingSMSMessageStatusEvent $event) { |
117
|
|
|
|
118
|
|
|
$request = SMSModeFactory::newCheckingSMSMessageStatusRequest($event->getCheckingSMSMessageStatus()); |
119
|
|
|
$response = $this->getApiProvider()->checkingSMSMessageStatus($request); |
120
|
|
|
|
121
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* On creating sub-account. |
126
|
|
|
* |
127
|
|
|
* @param CreatingSubAccountEvent $event The creating sub-account event. |
128
|
|
|
* @return CreatingSubAccountEvent Returns the creating sub-account event. |
129
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
130
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
131
|
|
|
*/ |
132
|
|
|
public function onCreatingSubAccount(CreatingSubAccountEvent $event) { |
133
|
|
|
|
134
|
|
|
$request = SMSModeFactory::newCreatingSubAccountRequest($event->getCreatingSubAccount()); |
135
|
|
|
$response = $this->getApiProvider()->creatingSubAccount($request); |
136
|
|
|
|
137
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* On deleting SMS. |
142
|
|
|
* |
143
|
|
|
* @param DeletingSMSEvent $event The deleting SMS event. |
144
|
|
|
* @return DeletingSMSEvent Returns the deleting SMS event. |
145
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
146
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
147
|
|
|
*/ |
148
|
|
|
public function onDeletingSMS(DeletingSMSEvent $event) { |
149
|
|
|
|
150
|
|
|
$request = SMSModeFactory::newDeletingSMSRequest($event->getDeletingSMS()); |
151
|
|
|
$response = $this->getApiProvider()->deletingSMS($request); |
152
|
|
|
|
153
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* On deleting sub-account. |
158
|
|
|
* |
159
|
|
|
* @param DeletingSubAccountEvent $event The deleting sub-account event. |
160
|
|
|
* @return DeletingSubAccountEvent Returns the deleting sub-account event. |
161
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
162
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
163
|
|
|
*/ |
164
|
|
|
public function onDeletingSubAccount(DeletingSubAccountEvent $event) { |
165
|
|
|
|
166
|
|
|
$request = SMSModeFactory::newDeletingSubAccountRequest($event->getDeletingSubAccount()); |
167
|
|
|
$response = $this->getApiProvider()->deletingSubAccount($request); |
168
|
|
|
|
169
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* On delivery report. |
174
|
|
|
* |
175
|
|
|
* @param DeliveryReportEvent $event The delivery report event. |
176
|
|
|
* @return DeliveryReportEvent Returns the delivery report event. |
177
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
178
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
179
|
|
|
*/ |
180
|
|
|
public function onDeliveryReport(DeliveryReportEvent $event) { |
181
|
|
|
|
182
|
|
|
$request = SMSModeFactory::newDeliveryReportRequest($event->getDeliveryReport()); |
183
|
|
|
$response = $this->getApiProvider()->deliveryReport($request); |
184
|
|
|
|
185
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* On retrieving SMS reply. |
190
|
|
|
* |
191
|
|
|
* @param RetrievingSMSReplyEvent $event The retrieving SMS reply event. |
192
|
|
|
* @return RetrievingSMSReplyEvent Returns the retrieving SMS reply event. |
193
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
194
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
195
|
|
|
*/ |
196
|
|
|
public function onRetrievingSMSReply(RetrievingSMSReplyEvent $event) { |
197
|
|
|
|
198
|
|
|
$request = SMSModeFactory::newRetrievingSMSReplyRequest($event->getRetrievingSMSReply()); |
199
|
|
|
$response = $this->getApiProvider()->retrievingSMSReply($request); |
200
|
|
|
|
201
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* On sending SMS batch. |
206
|
|
|
* |
207
|
|
|
* @param SendingSMSBatchEvent $event The sending SMS batch event. |
208
|
|
|
* @return SendingSMSBatchEvent Returns the sending SMS batch event. |
209
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
210
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
211
|
|
|
*/ |
212
|
|
|
public function onSendingSMSBatch(SendingSMSBatchEvent $event) { |
213
|
|
|
|
214
|
|
|
$request = SMSModeFactory::newSendingSMSBatchRequest($event->getSendingSMSBatch()); |
215
|
|
|
$response = $this->getApiProvider()->sendingSMSBatch($request); |
216
|
|
|
|
217
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* On sending SMS message. |
222
|
|
|
* |
223
|
|
|
* @param SendingSMSMessageEvent $event The sending SMS message event. |
224
|
|
|
* @return SendingSMSMessageEvent Returns the sending SMS message event. |
225
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
226
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
227
|
|
|
*/ |
228
|
|
|
public function onSendingSMSMessage(SendingSMSMessageEvent $event) { |
229
|
|
|
|
230
|
|
|
$request = SMSModeFactory::newSendingSMSMessageRequest($event->getSendingSMSMessage()); |
231
|
|
|
$response = $this->getApiProvider()->sendingSMSMessage($request); |
232
|
|
|
|
233
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* On sending text-to-speech. |
238
|
|
|
* |
239
|
|
|
* @param SendingTextToSpeechSMSEvent $event The sending text-to-speech event. |
240
|
|
|
* @return SendingTextToSpeechSMSEvent Returns the sending text-to-speech event. |
241
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
242
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
243
|
|
|
*/ |
244
|
|
|
public function onSendingTextToSpeechSMS(SendingTextToSpeechSMSEvent $event) { |
245
|
|
|
|
246
|
|
|
$request = SMSModeFactory::newSendingTextToSpeechSMSRequest($event->getSendingTextToSpeechSMS()); |
247
|
|
|
$response = $this->getApiProvider()->sendingTextToSpeechSMS($request); |
248
|
|
|
|
249
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* On sending unicode SMS. |
254
|
|
|
* |
255
|
|
|
* @param SendingUnicodeSMSEvent $event The sending unicode SMS event. |
256
|
|
|
* @return SendingUnicodeSMSEvent Returns the sending unicode SMS event. |
257
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
258
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
259
|
|
|
*/ |
260
|
|
|
public function onSendingUnicodeSMS(SendingUnicodeSMSEvent $event) { |
261
|
|
|
|
262
|
|
|
$request = SMSModeFactory::newSendingUnicodeSMSRequest($event->getSendingUnicodeSMS()); |
263
|
|
|
$response = $this->getApiProvider()->sendingUnicodeSMS($request); |
264
|
|
|
|
265
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* On sent SMS message lis. |
270
|
|
|
* |
271
|
|
|
* @param SentSMSMessageListEvent $event The sent SMS message list event. |
272
|
|
|
* @return SentSMSMessageListEvent Returns the sent SMS message list event. |
273
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
274
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
275
|
|
|
*/ |
276
|
|
|
public function onSentSMSMessageList(SentSMSMessageListEvent $event) { |
277
|
|
|
|
278
|
|
|
$request = SMSModeFactory::newSentSMSMessageListRequest($event->getSentSMSMessageList()); |
279
|
|
|
$response = $this->getApiProvider()->sentSMSMessageList($request); |
280
|
|
|
|
281
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* On transferring credits. |
286
|
|
|
* |
287
|
|
|
* @param TransferringCreditsEvent $event The transferring credits event. |
288
|
|
|
* @return TransferringCreditsEvent Returns the transferring credits event. |
289
|
|
|
* @throws APIException Throws an API exception if an error occurs. |
290
|
|
|
* @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
291
|
|
|
*/ |
292
|
|
|
public function onTransferringCredits(TransferringCreditsEvent $event) { |
293
|
|
|
|
294
|
|
|
$request = SMSModeFactory::newTransferringCreditsRequest($event->getTransferringCredits()); |
295
|
|
|
$response = $this->getApiProvider()->transferringCredits($request); |
296
|
|
|
|
297
|
|
|
return $this->beforeReturnEvent($event, $request, $response); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Set the access token. |
302
|
|
|
* |
303
|
|
|
* @param string $accessToken The access token. |
304
|
|
|
* @return SMSModeEventListener Returns this event listener. |
305
|
|
|
*/ |
306
|
|
|
public function setAccessToken($accessToken) { |
307
|
|
|
$this->getApiProvider()->getAuthentication()->setAccessToken($accessToken); |
308
|
|
|
return $this; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Set the API provider. |
313
|
|
|
* |
314
|
|
|
* @param APIProvider $apiProvider The API provider. |
315
|
|
|
* @return SMSModeEventListener Returns this event listener. |
316
|
|
|
*/ |
317
|
|
|
protected function setApiProvider(ApiProvider $apiProvider) { |
318
|
|
|
$this->apiProvider = $apiProvider; |
319
|
|
|
return $this; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Set the pass. |
324
|
|
|
* |
325
|
|
|
* @param string $pass The pass. |
326
|
|
|
* @return SMSModeEventListener Returns this event listener. |
327
|
|
|
*/ |
328
|
|
|
public function setPass($pass) { |
329
|
|
|
$this->getApiProvider()->getAuthentication()->setPass($pass); |
330
|
|
|
return $this; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Set the pseudo. |
335
|
|
|
* |
336
|
|
|
* @param string $pseudo The pseudo. |
337
|
|
|
* @return SMSModeEventListener Returns this event listener. |
338
|
|
|
*/ |
339
|
|
|
public function setPseudo($pseudo) { |
340
|
|
|
$this->getApiProvider()->getAuthentication()->setPseudo($pseudo); |
341
|
|
|
return $this; |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
|