Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Notifications;
4
 
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
7
use Illuminate\Contracts\Queue\ShouldQueue;
8
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
9
use Illuminate\Database\Eloquent\Model;
10
use Illuminate\Queue\InteractsWithQueue;
11
use Illuminate\Queue\SerializesModels;
12
use Illuminate\Support\Collection;
13
 
14
class SendQueuedNotifications implements ShouldQueue
15
{
16
    use InteractsWithQueue, Queueable, SerializesModels;
17
 
18
    /**
19
     * The notifiable entities that should receive the notification.
20
     *
21
     * @var \Illuminate\Support\Collection
22
     */
23
    public $notifiables;
24
 
25
    /**
26
     * The notification to be sent.
27
     *
28
     * @var \Illuminate\Notifications\Notification
29
     */
30
    public $notification;
31
 
32
    /**
33
     * All of the channels to send the notification to.
34
     *
35
     * @var array
36
     */
37
    public $channels;
38
 
39
    /**
40
     * The number of times the job may be attempted.
41
     *
42
     * @var int
43
     */
44
    public $tries;
45
 
46
    /**
47
     * The number of seconds the job can run before timing out.
48
     *
49
     * @var int
50
     */
51
    public $timeout;
52
 
53
    /**
54
     * The maximum number of unhandled exceptions to allow before failing.
55
     *
56
     * @var int
57
     */
58
    public $maxExceptions;
59
 
60
    /**
61
     * Indicates if the job should be encrypted.
62
     *
63
     * @var bool
64
     */
65
    public $shouldBeEncrypted = false;
66
 
67
    /**
68
     * Create a new job instance.
69
     *
70
     * @param  \Illuminate\Notifications\Notifiable|\Illuminate\Support\Collection  $notifiables
71
     * @param  \Illuminate\Notifications\Notification  $notification
72
     * @param  array|null  $channels
73
     * @return void
74
     */
75
    public function __construct($notifiables, $notification, array $channels = null)
76
    {
77
        $this->channels = $channels;
78
        $this->notification = $notification;
79
        $this->notifiables = $this->wrapNotifiables($notifiables);
80
        $this->tries = property_exists($notification, 'tries') ? $notification->tries : null;
81
        $this->timeout = property_exists($notification, 'timeout') ? $notification->timeout : null;
82
        $this->maxExceptions = property_exists($notification, 'maxExceptions') ? $notification->maxExceptions : null;
83
        $this->afterCommit = property_exists($notification, 'afterCommit') ? $notification->afterCommit : null;
84
        $this->shouldBeEncrypted = $notification instanceof ShouldBeEncrypted;
85
    }
86
 
87
    /**
88
     * Wrap the notifiable(s) in a collection.
89
     *
90
     * @param  \Illuminate\Notifications\Notifiable|\Illuminate\Support\Collection  $notifiables
91
     * @return \Illuminate\Support\Collection
92
     */
93
    protected function wrapNotifiables($notifiables)
94
    {
95
        if ($notifiables instanceof Collection) {
96
            return $notifiables;
97
        } elseif ($notifiables instanceof Model) {
98
            return EloquentCollection::wrap($notifiables);
99
        }
100
 
101
        return Collection::wrap($notifiables);
102
    }
103
 
104
    /**
105
     * Send the notifications.
106
     *
107
     * @param  \Illuminate\Notifications\ChannelManager  $manager
108
     * @return void
109
     */
110
    public function handle(ChannelManager $manager)
111
    {
112
        $manager->sendNow($this->notifiables, $this->notification, $this->channels);
113
    }
114
 
115
    /**
116
     * Get the display name for the queued job.
117
     *
118
     * @return string
119
     */
120
    public function displayName()
121
    {
122
        return get_class($this->notification);
123
    }
124
 
125
    /**
126
     * Call the failed method on the notification instance.
127
     *
128
     * @param  \Throwable  $e
129
     * @return void
130
     */
131
    public function failed($e)
132
    {
133
        if (method_exists($this->notification, 'failed')) {
134
            $this->notification->failed($e);
135
        }
136
    }
137
 
138
    /**
139
     * Get the number of seconds before a released notification will be available.
140
     *
141
     * @return mixed
142
     */
143
    public function backoff()
144
    {
145
        if (! method_exists($this->notification, 'backoff') && ! isset($this->notification->backoff)) {
146
            return;
147
        }
148
 
149
        return $this->notification->backoff ?? $this->notification->backoff();
150
    }
151
 
152
    /**
153
     * Determine the time at which the job should timeout.
154
     *
155
     * @return \DateTime|null
156
     */
157
    public function retryUntil()
158
    {
159
        if (! method_exists($this->notification, 'retryUntil') && ! isset($this->notification->retryUntil)) {
160
            return;
161
        }
162
 
163
        return $this->notification->retryUntil ?? $this->notification->retryUntil();
164
    }
165
 
166
    /**
167
     * Prepare the instance for cloning.
168
     *
169
     * @return void
170
     */
171
    public function __clone()
172
    {
173
        $this->notifiables = clone $this->notifiables;
174
        $this->notification = clone $this->notification;
175
    }
176
}