1 | <?php |
||||
2 | |||||
3 | namespace NotificationChannels\RayganSms; |
||||
4 | |||||
5 | use DomainException; |
||||
6 | use Illuminate\Notifications\Notification; |
||||
7 | use NotificationChannels\RayganSms\Events\MessageWasSent; |
||||
8 | use NotificationChannels\RayganSms\Events\SendingMessage; |
||||
9 | use NotificationChannels\RayganSms\Exceptions\CouldNotSendNotification; |
||||
10 | use Trez\RayganSms\Facades\RayganSms; |
||||
11 | |||||
12 | class RayganSmsChannel |
||||
13 | { |
||||
14 | public function __construct() |
||||
15 | { |
||||
16 | } |
||||
17 | |||||
18 | /** |
||||
19 | * Send the given notification. |
||||
20 | * |
||||
21 | * @param mixed $notifiable |
||||
22 | * @param Notification $notification |
||||
23 | * |
||||
24 | * @return void |
||||
25 | */ |
||||
26 | public function send($notifiable, Notification $notification) |
||||
27 | { |
||||
28 | if (!$this->shouldSendMessage($notifiable, $notification)) { |
||||
29 | return; |
||||
30 | } |
||||
31 | |||||
32 | if (!$to = $notifiable->routeNotificationFor('raygansms')) { |
||||
33 | return; |
||||
34 | } |
||||
35 | |||||
36 | $message = $notification->{'toRayganSms'}($notifiable); |
||||
37 | |||||
38 | if (is_string($message)) { |
||||
39 | $message = new RayganSmsMessage($message); |
||||
40 | } |
||||
41 | |||||
42 | try { |
||||
43 | RayganSms::sendMessage($to, $message->getContent()); |
||||
44 | |||||
45 | event(new MessageWasSent($notifiable, $notification)); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
46 | } catch (DomainException $e) { |
||||
47 | throw CouldNotSendNotification::serviceRespondedWithAnError($e); |
||||
48 | } |
||||
49 | } |
||||
50 | |||||
51 | /** |
||||
52 | * Check if we can send the notification. |
||||
53 | * |
||||
54 | * @param $notifiable |
||||
55 | * @param Notification $notification |
||||
56 | * |
||||
57 | * @return bool |
||||
58 | */ |
||||
59 | protected function shouldSendMessage($notifiable, Notification $notification) |
||||
60 | { |
||||
61 | return event(new SendingMessage($notifiable, $notification), [], true) !== false; |
||||
0 ignored issues
–
show
The function
event was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
62 | } |
||||
63 | } |
||||
64 |