1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Author: Facundo J Gonzalez |
4
|
|
|
* Date: 17/11/2017. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace NotificationChannels\SMSC; |
8
|
|
|
|
9
|
|
|
use Illuminate\Notifications\Notification; |
10
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
11
|
|
|
use NotificationChannels\SMSC\Events\MessageWasSent; |
12
|
|
|
use NotificationChannels\SMSC\Events\SendingMessage; |
13
|
|
|
use NotificationChannels\SMSC\Clients\SMSCClientInterface; |
14
|
|
|
use NotificationChannels\SMSC\Clients\SMSCApiResponseInterface; |
15
|
|
|
use NotificationChannels\SMSC\Exceptions\CouldNotSendNotification; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class SMSCChannel. |
19
|
|
|
*/ |
20
|
|
|
final class SMSCChannel |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The guzzle http client. |
24
|
|
|
* |
25
|
|
|
* @var SMSCClientInterface |
26
|
|
|
*/ |
27
|
|
|
private $client; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The Laravel event dispatcher implementation. |
31
|
|
|
* |
32
|
|
|
* @var Dispatcher |
33
|
|
|
*/ |
34
|
|
|
private $dispatcher; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* SMSCChannel constructor. |
38
|
|
|
* |
39
|
|
|
* @param SMSCClientInterface $client |
40
|
|
|
* @param Dispatcher $dispatcher |
41
|
|
|
*/ |
42
|
|
|
public function __construct(SMSCClientInterface $client, Dispatcher $dispatcher) |
43
|
|
|
{ |
44
|
|
|
$this->client = $client; |
45
|
|
|
$this->dispatcher = $dispatcher; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Send the given notification. |
50
|
|
|
* |
51
|
|
|
* @param mixed $notifiable |
52
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
53
|
|
|
* @throws \NotificationChannels\SMSC\Exceptions\CouldNotSendNotification |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function send($notifiable, Notification $notification) |
57
|
|
|
{ |
58
|
|
|
$to = $notifiable->routeNotificationFor('SMSC'); |
59
|
|
|
|
60
|
|
|
if (empty($to)) { |
61
|
|
|
throw CouldNotSendNotification::missingRecipient(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$message = $notification->toSMSC($notifiable); |
|
|
|
|
65
|
|
|
|
66
|
|
|
if (is_string($message)) { |
67
|
|
|
$message = new SMSCMessage($message, $to); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (strlen($message->content()) > 160) { |
71
|
|
|
throw CouldNotSendNotification::contentLengthLimitExceeded(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->client->addToRequest($message); |
75
|
|
|
$this->fireSendingEvent($message); |
76
|
|
|
$response = $this->sendMessage(); |
77
|
|
|
$this->fireSentEvent($message, $response); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Send the message. |
82
|
|
|
* |
83
|
|
|
* @return SMSCApiResponseInterface |
84
|
|
|
*/ |
85
|
|
|
private function sendMessage() |
86
|
|
|
{ |
87
|
|
|
$response = $this->client->sendRequest(); |
88
|
|
|
|
89
|
|
|
return $response; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Fire the sending event for the prepared message. |
94
|
|
|
* |
95
|
|
|
* @param SMSCMessage $message |
96
|
|
|
*/ |
97
|
|
|
private function fireSendingEvent(SMSCMessage $message) |
98
|
|
|
{ |
99
|
|
|
$this->dispatcher->fire(new SendingMessage($message)); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Fire the sent event for the message. |
104
|
|
|
* |
105
|
|
|
* @param SMSCMessage $message |
106
|
|
|
* @param SMSCApiResponseInterface $response |
107
|
|
|
*/ |
108
|
|
|
private function fireSentEvent(SMSCMessage $message, SMSCApiResponseInterface $response) |
109
|
|
|
{ |
110
|
|
|
$this->dispatcher->fire(new MessageWasSent($message, $response)); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.