SendQueuedNotifications.php
2.51 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Illuminate\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendQueuedNotifications implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* The notifiable entities that should receive the notification.
*
* @var \Illuminate\Support\Collection
*/
public $notifiables;
/**
* The notification to be sent.
*
* @var \Illuminate\Notifications\Notification
*/
public $notification;
/**
* All of the channels to send the notification to.
*
* @var array
*/
public $channels;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries;
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout;
/**
* Create a new job instance.
*
* @param \Illuminate\Support\Collection $notifiables
* @param \Illuminate\Notifications\Notification $notification
* @param array $channels
* @return void
*/
public function __construct($notifiables, $notification, array $channels = null)
{
$this->channels = $channels;
$this->notifiables = $notifiables;
$this->notification = $notification;
$this->tries = property_exists($notification, 'tries') ? $notification->tries : null;
$this->timeout = property_exists($notification, 'timeout') ? $notification->timeout : null;
}
/**
* Send the notifications.
*
* @param \Illuminate\Notifications\ChannelManager $manager
* @return void
*/
public function handle(ChannelManager $manager)
{
$manager->sendNow($this->notifiables, $this->notification, $this->channels);
}
/**
* Get the display name for the queued job.
*
* @return string
*/
public function displayName()
{
return get_class($this->notification);
}
/**
* Call the failed method on the notification instance.
*
* @param \Exception $e
* @return void
*/
public function failed($e)
{
if (method_exists($this->notification, 'failed')) {
$this->notification->failed($e);
}
}
/**
* Prepare the instance for cloning.
*
* @return void
*/
public function __clone()
{
$this->notifiables = clone $this->notifiables;
$this->notification = clone $this->notification;
}
}