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\Mail;
4
 
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Contracts\Mail\Factory as MailFactory;
7
use Illuminate\Contracts\Mail\Mailable as MailableContract;
8
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
9
use Illuminate\Queue\InteractsWithQueue;
10
 
11
class SendQueuedMailable
12
{
13
    use Queueable, InteractsWithQueue;
14
 
15
    /**
16
     * The mailable message instance.
17
     *
18
     * @var \Illuminate\Contracts\Mail\Mailable
19
     */
20
    public $mailable;
21
 
22
    /**
23
     * The number of times the job may be attempted.
24
     *
25
     * @var int
26
     */
27
    public $tries;
28
 
29
    /**
30
     * The number of seconds the job can run before timing out.
31
     *
32
     * @var int
33
     */
34
    public $timeout;
35
 
36
    /**
37
     * The maximum number of unhandled exceptions to allow before failing.
38
     *
39
     * @return int|null
40
     */
41
    public $maxExceptions;
42
 
43
    /**
44
     * Indicates if the job should be encrypted.
45
     *
46
     * @var bool
47
     */
48
    public $shouldBeEncrypted = false;
49
 
50
    /**
51
     * Create a new job instance.
52
     *
53
     * @param  \Illuminate\Contracts\Mail\Mailable  $mailable
54
     * @return void
55
     */
56
    public function __construct(MailableContract $mailable)
57
    {
58
        $this->mailable = $mailable;
59
        $this->tries = property_exists($mailable, 'tries') ? $mailable->tries : null;
60
        $this->timeout = property_exists($mailable, 'timeout') ? $mailable->timeout : null;
61
        $this->maxExceptions = property_exists($mailable, 'maxExceptions') ? $mailable->maxExceptions : null;
62
        $this->afterCommit = property_exists($mailable, 'afterCommit') ? $mailable->afterCommit : null;
63
        $this->shouldBeEncrypted = $mailable instanceof ShouldBeEncrypted;
64
    }
65
 
66
    /**
67
     * Handle the queued job.
68
     *
69
     * @param  \Illuminate\Contracts\Mail\Factory  $factory
70
     * @return void
71
     */
72
    public function handle(MailFactory $factory)
73
    {
74
        $this->mailable->send($factory);
75
    }
76
 
77
    /**
78
     * Get the number of seconds before a released mailable will be available.
79
     *
80
     * @return mixed
81
     */
82
    public function backoff()
83
    {
84
        if (! method_exists($this->mailable, 'backoff') && ! isset($this->mailable->backoff)) {
85
            return;
86
        }
87
 
88
        return $this->mailable->backoff ?? $this->mailable->backoff();
89
    }
90
 
91
    /**
92
     * Determine the time at which the job should timeout.
93
     *
94
     * @return \DateTime|null
95
     */
96
    public function retryUntil()
97
    {
98
        if (! method_exists($this->mailable, 'retryUntil') && ! isset($this->mailable->retryUntil)) {
99
            return;
100
        }
101
 
102
        return $this->mailable->retryUntil ?? $this->mailable->retryUntil();
103
    }
104
 
105
    /**
106
     * Call the failed method on the mailable instance.
107
     *
108
     * @param  \Throwable  $e
109
     * @return void
110
     */
111
    public function failed($e)
112
    {
113
        if (method_exists($this->mailable, 'failed')) {
114
            $this->mailable->failed($e);
115
        }
116
    }
117
 
118
    /**
119
     * Get the display name for the queued job.
120
     *
121
     * @return string
122
     */
123
    public function displayName()
124
    {
125
        return get_class($this->mailable);
126
    }
127
 
128
    /**
129
     * Prepare the instance for cloning.
130
     *
131
     * @return void
132
     */
133
    public function __clone()
134
    {
135
        $this->mailable = clone $this->mailable;
136
    }
137
}