1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Pushover; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
6
|
|
|
use Illuminate\Notifications\Events\NotificationFailed; |
7
|
|
|
use Illuminate\Notifications\Notification; |
8
|
|
|
use NotificationChannels\Pushover\Exceptions\ServiceCommunicationError; |
9
|
|
|
|
10
|
|
|
class PushoverChannel |
11
|
|
|
{ |
12
|
|
|
/** @var Pushover */ |
13
|
|
|
protected $pushover; |
14
|
|
|
|
15
|
|
|
/** @var Dispatcher */ |
16
|
|
|
protected $events; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Create a new Pushover channel instance. |
20
|
|
|
* |
21
|
|
|
* @param Pushover $pushover |
22
|
|
|
*/ |
23
|
6 |
|
public function __construct(Pushover $pushover, Dispatcher $events) |
24
|
|
|
{ |
25
|
6 |
|
$this->pushover = $pushover; |
26
|
6 |
|
$this->events = $events; |
27
|
6 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Send the given notification. |
31
|
|
|
* |
32
|
|
|
* @param mixed $notifiable |
33
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
34
|
|
|
* |
35
|
|
|
* @throws \NotificationChannels\Pushover\Exceptions\CouldNotSendNotification |
36
|
|
|
*/ |
37
|
6 |
|
public function send($notifiable, Notification $notification) |
38
|
|
|
{ |
39
|
6 |
|
if (! $pushoverReceiver = $notifiable->routeNotificationFor('pushover')) { |
40
|
1 |
|
return; |
41
|
|
|
} |
42
|
|
|
|
43
|
5 |
|
if (is_string($pushoverReceiver)) { |
44
|
2 |
|
$pushoverReceiver = PushoverReceiver::withUserKey($pushoverReceiver); |
45
|
|
|
} |
46
|
|
|
|
47
|
5 |
|
$message = $notification->toPushover($notifiable); |
|
|
|
|
48
|
|
|
|
49
|
|
|
try { |
50
|
5 |
|
$this->pushover->send(array_merge($message->toArray(), $pushoverReceiver->toArray())); |
51
|
1 |
|
} catch (ServiceCommunicationError $serviceCommunicationError) { |
52
|
1 |
|
$this->fireFailedEvent($notifiable, $notification, $serviceCommunicationError->getMessage()); |
53
|
|
|
} |
54
|
5 |
|
} |
55
|
|
|
|
56
|
1 |
|
protected function fireFailedEvent($notifiable, $notification, $message) |
57
|
|
|
{ |
58
|
1 |
|
$this->events->fire( |
|
|
|
|
59
|
1 |
|
new NotificationFailed($notifiable, $notification, 'pushover', [$message]) |
60
|
|
|
); |
61
|
1 |
|
} |
62
|
|
|
} |
63
|
|
|
|
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.