|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Neo\PusherBeams; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Events\Dispatcher; |
|
6
|
|
|
use Illuminate\Notifications\Events\NotificationFailed; |
|
7
|
|
|
use Illuminate\Notifications\Notification; |
|
8
|
|
|
use Pusher\PushNotifications\PushNotifications; |
|
9
|
|
|
|
|
10
|
|
|
class PusherBeams |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var \Pusher\PushNotifications\PushNotifications |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $beams; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param \Pusher\PushNotifications\PushNotifications $beams |
|
19
|
|
|
* @param \Illuminate\Events\Dispatcher $events |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct(PushNotifications $beams, Dispatcher $events) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->beams = $beams; |
|
24
|
|
|
$this->events = $events; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \Illuminate\Events\Dispatcher |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $events; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Send the given notification. |
|
34
|
|
|
* |
|
35
|
|
|
* @param mixed $notifiable |
|
36
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
37
|
|
|
*/ |
|
38
|
|
|
public function send($notifiable, Notification $notification) |
|
39
|
|
|
{ |
|
40
|
|
|
if (method_exists($notification, 'pushNotificationInterest')) { |
|
41
|
|
|
$interest = $notification->pushNotificationInterest(); |
|
|
|
|
|
|
42
|
|
|
} else { |
|
43
|
|
|
$interest = $notifiable->routeNotificationFor('PusherBeams') |
|
44
|
|
|
?: $this->interestName($notifiable); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (is_string($interest)) { |
|
48
|
|
|
$interest = [$interest]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
try { |
|
52
|
|
|
$response = $this->beams->publish( |
|
|
|
|
|
|
53
|
|
|
$interest, |
|
54
|
|
|
$notification->toPushNotification($notifiable)->toArray() |
|
|
|
|
|
|
55
|
|
|
); |
|
56
|
|
|
} catch (\Exception $e) { |
|
57
|
|
|
$this->events->fire( |
|
58
|
|
|
new NotificationFailed($notifiable, $notification, 'pusher-beams') |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the interest name for the notifiable. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $notifiable |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function interestName($notifiable) |
|
70
|
|
|
{ |
|
71
|
|
|
$class = str_replace('\\', '.', get_class($notifiable)); |
|
72
|
|
|
|
|
73
|
|
|
return $class . '.' . $notifiable->getKey(); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
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.