-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPushbulletChannel.php
More file actions
67 lines (54 loc) · 1.76 KB
/
Copy pathPushbulletChannel.php
File metadata and controls
67 lines (54 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
namespace NotificationChannels\Pushbullet;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushbullet\Targets\Device;
use NotificationChannels\Pushbullet\Targets\Email;
use NotificationChannels\Pushbullet\Targets\Targetable;
class PushbulletChannel
{
/** @var \NotificationChannels\Pushbullet\Pushbullet */
private $pushbullet;
/**
* @param \NotificationChannels\Pushbullet\Pushbullet $pushbullet
*/
public function __construct(Pushbullet $pushbullet)
{
$this->pushbullet = $pushbullet;
}
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
*
* @throws \NotificationChannels\Pushbullet\Exceptions\CouldNotSendNotification
*/
public function send($notifiable, Notification $notification): void
{
if (! $target = $this->getTarget($notifiable)) {
return;
}
/** @var \NotificationChannels\Pushbullet\PushbulletMessage $message */
$message = $notification->toPushbullet($notifiable)->target($target);
$this->pushbullet->send($message->toArray());
}
/**
* @param $notifiable
* @return \NotificationChannels\Pushbullet\Targets\Targetable|null
*/
private function getTarget($notifiable): ?Targetable
{
if (! $target = $notifiable->routeNotificationFor('pushbullet')) {
return null;
}
if ($target instanceof Targetable) {
return $target;
}
$target = (string) $target;
if (filter_var($target, FILTER_VALIDATE_EMAIL) !== false) {
return new Email($target);
}
return new Device($target);
}
}