1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rich2k\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
|
|
|
if (method_exists($this->beams, 'publishToInterests')) { |
53
|
|
|
$response = $this->beams->publishToInterests( |
|
|
|
|
54
|
|
|
$interest, |
55
|
|
|
$notification->toPusherBeamsNotification($notifiable)->toArray() |
|
|
|
|
56
|
|
|
); |
57
|
|
|
} else { |
58
|
|
|
$response = $this->beams->publish( |
|
|
|
|
59
|
|
|
$interest, |
60
|
|
|
$notification->toPusherBeamsNotification($notifiable)->toArray() |
|
|
|
|
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} catch (\Exception $e) { |
64
|
|
|
$this->events->fire( |
65
|
|
|
new NotificationFailed($notifiable, $notification, 'pusher-beams') |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the interest name for the notifiable. |
72
|
|
|
* |
73
|
|
|
* @param string $notifiable |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
protected function interestName($notifiable) |
77
|
|
|
{ |
78
|
|
|
$class = str_replace('\\', '.', get_class($notifiable)); |
79
|
|
|
|
80
|
|
|
return $class . '.' . $notifiable->getKey(); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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.