|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Pushwoosh; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Notification; |
|
6
|
|
|
use Illuminate\Support\Arr; |
|
7
|
|
|
|
|
8
|
|
|
class PushwooshChannel |
|
9
|
|
|
{ |
|
10
|
|
|
protected $pushwoosh; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Create a new Pushwoosh notification channel. |
|
14
|
|
|
* |
|
15
|
|
|
* @param \NotificationChannels\Pushwoosh\Pushwoosh $pushwoosh |
|
16
|
|
|
* @return void |
|
17
|
|
|
*/ |
|
18
|
18 |
|
public function __construct(Pushwoosh $pushwoosh) |
|
19
|
|
|
{ |
|
20
|
18 |
|
$this->pushwoosh = $pushwoosh; |
|
21
|
18 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Parse the message. |
|
25
|
|
|
* |
|
26
|
|
|
* @param mixed $message |
|
27
|
|
|
* @return \NotificationChannels\Pushwoosh\PushwooshMessage |
|
28
|
|
|
*/ |
|
29
|
6 |
|
protected function parseMessage($message) |
|
30
|
|
|
{ |
|
31
|
6 |
|
return new PushwooshMessage((string)$message); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Parse the recipient(s). |
|
36
|
|
|
* |
|
37
|
|
|
* @param mixed $recipients |
|
38
|
|
|
* @return \NotificationChannels\Pushwoosh\PushwooshRecipient |
|
39
|
|
|
*/ |
|
40
|
6 |
|
protected function parseRecipients($recipients) |
|
41
|
|
|
{ |
|
42
|
6 |
|
return (new PushwooshRecipient)->device(...Arr::wrap($recipients)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Send the given notification. |
|
47
|
|
|
* |
|
48
|
|
|
* @param \Illuminate\Notifications\RoutesNotifications $notifiable |
|
49
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
18 |
|
public function send($notifiable, Notification $notification) |
|
53
|
|
|
{ |
|
54
|
18 |
|
$recipients = $notifiable->routeNotificationFor('pushwoosh', $notification); |
|
55
|
|
|
|
|
56
|
|
|
/** @noinspection PhpUndefinedMethodInspection */ |
|
57
|
18 |
|
if (!$recipients || !$message = $notification->toPushwoosh($notifiable)) { |
|
58
|
12 |
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
6 |
|
if (!$message instanceof PushwooshMessage) { |
|
62
|
6 |
|
$message = $this->parseMessage($message)->associate($notification); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
6 |
|
if (!$recipients instanceof PushwooshRecipient) { |
|
66
|
6 |
|
$recipients = $this->parseRecipients($recipients); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
6 |
|
$this->pushwoosh->send($message)->to($recipients); |
|
70
|
6 |
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|