1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimonKub\Laravel\Notifications\Sipgate; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Config; |
6
|
|
|
use Illuminate\Notifications\Notification; |
7
|
|
|
use SimonKub\Laravel\Notifications\Sipgate\Exceptions\CouldNotSendNotification; |
8
|
|
|
|
9
|
|
|
class SipgateChannel |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var SipgateClient |
13
|
|
|
*/ |
14
|
|
|
protected $client; |
15
|
|
|
|
16
|
|
|
public function __construct(SipgateClient $client) |
17
|
|
|
{ |
18
|
|
|
$this->client = $client; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Send the given notification. |
23
|
|
|
* |
24
|
|
|
* @param mixed $notifiable |
25
|
|
|
* @param Notification $notification |
26
|
|
|
* |
27
|
|
|
* @throws CouldNotSendNotification |
28
|
|
|
*/ |
29
|
|
|
public function send($notifiable, Notification $notification) |
30
|
|
|
{ |
31
|
|
|
/** @var SipgateMessage $message */ |
32
|
|
|
$message = $notification->toSipgate($notifiable); |
|
|
|
|
33
|
|
|
|
34
|
|
|
$this->addRecipient($message, $notifiable); |
35
|
|
|
|
36
|
|
|
$this->addSmsId($message); |
37
|
|
|
|
38
|
|
|
$this->client->send($message); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param SipgateMessage $message |
43
|
|
|
* @param $notifiable |
44
|
|
|
* @throws CouldNotSendNotification |
45
|
|
|
*/ |
46
|
|
|
protected function addRecipient(SipgateMessage $message, $notifiable) |
47
|
|
|
{ |
48
|
|
|
if ($message->getRecipient()) { |
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($recipient = $notifiable->routeNotificationFor('sipgate', $notifiable)) { |
53
|
|
|
$message->recipient($recipient); |
54
|
|
|
|
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
throw CouldNotSendNotification::noRecipient(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param SipgateMessage $message |
63
|
|
|
* @throws CouldNotSendNotification |
64
|
|
|
*/ |
65
|
|
|
protected function addSmsId(SipgateMessage $message) |
66
|
|
|
{ |
67
|
|
|
if ($message->getSmsId()) { |
68
|
|
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if ($smsId = Config::get('services.sipgate.smsId')) { |
72
|
|
|
$message->smsId($smsId); |
73
|
|
|
|
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
throw CouldNotSendNotification::noSmsId(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
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.