1 | <?php |
||
2 | |||
3 | namespace Andreshg112\PusherApiNotifications; |
||
4 | |||
5 | use Andreshg112\PusherApiNotifications\Exceptions\CouldNotSendNotification; |
||
6 | use Illuminate\Notifications\Notification; |
||
7 | |||
8 | class PusherApiChannel |
||
9 | { |
||
10 | /** @var \Pusher|\Pusher\Pusher */ |
||
11 | protected $pusher; |
||
12 | |||
13 | 2 | public function __construct(\Pusher $pusher) |
|
14 | { |
||
15 | 2 | $this->pusher = $pusher; |
|
16 | 2 | } |
|
17 | |||
18 | /** |
||
19 | * Send the given notification. |
||
20 | * |
||
21 | * @param mixed $notifiable |
||
22 | * @param \Illuminate\Notifications\Notification $notification |
||
23 | * |
||
24 | * @throws \Andreshg112\PusherApiNotifications\Exceptions\CouldNotSendNotification |
||
25 | */ |
||
26 | 2 | public function send($notifiable, Notification $notification) |
|
27 | { |
||
28 | /** @var PusherApiMessage $pusherApiMessage */ |
||
29 | 2 | $pusherApiMessage = $notification->toApiNotification($notifiable); |
|
30 | |||
31 | 2 | $message = $pusherApiMessage->toArray(); |
|
32 | |||
33 | 2 | $response = $this->pusher::trigger( |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
34 | 2 | $message['channels'], |
|
35 | 2 | $message['event'], |
|
36 | 2 | $message['data'], |
|
37 | 2 | $message['socketId'] ?? null, |
|
38 | 2 | $message['debug'] ?? false, |
|
39 | 2 | $message['alreadyEncoded'] ?? false |
|
40 | ); |
||
41 | |||
42 | 2 | if (! $response) { |
|
43 | 1 | throw CouldNotSendNotification::serviceRespondedWithAnError($response); |
|
44 | } |
||
45 | 1 | } |
|
46 | } |
||
47 |