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\Contracts\Mail\Mailable as MailableContract;
6
use Illuminate\Contracts\Mail\Mailer as MailerContract;
7
use Illuminate\Contracts\Translation\HasLocalePreference;
8
use Illuminate\Support\Traits\Conditionable;
9
 
10
class PendingMail
11
{
12
    use Conditionable;
13
 
14
    /**
15
     * The mailer instance.
16
     *
17
     * @var \Illuminate\Contracts\Mail\Mailer
18
     */
19
    protected $mailer;
20
 
21
    /**
22
     * The locale of the message.
23
     *
24
     * @var string
25
     */
26
    protected $locale;
27
 
28
    /**
29
     * The "to" recipients of the message.
30
     *
31
     * @var array
32
     */
33
    protected $to = [];
34
 
35
    /**
36
     * The "cc" recipients of the message.
37
     *
38
     * @var array
39
     */
40
    protected $cc = [];
41
 
42
    /**
43
     * The "bcc" recipients of the message.
44
     *
45
     * @var array
46
     */
47
    protected $bcc = [];
48
 
49
    /**
50
     * Create a new mailable mailer instance.
51
     *
52
     * @param  \Illuminate\Contracts\Mail\Mailer  $mailer
53
     * @return void
54
     */
55
    public function __construct(MailerContract $mailer)
56
    {
57
        $this->mailer = $mailer;
58
    }
59
 
60
    /**
61
     * Set the locale of the message.
62
     *
63
     * @param  string  $locale
64
     * @return $this
65
     */
66
    public function locale($locale)
67
    {
68
        $this->locale = $locale;
69
 
70
        return $this;
71
    }
72
 
73
    /**
74
     * Set the recipients of the message.
75
     *
76
     * @param  mixed  $users
77
     * @return $this
78
     */
79
    public function to($users)
80
    {
81
        $this->to = $users;
82
 
83
        if (! $this->locale && $users instanceof HasLocalePreference) {
84
            $this->locale($users->preferredLocale());
85
        }
86
 
87
        return $this;
88
    }
89
 
90
    /**
91
     * Set the recipients of the message.
92
     *
93
     * @param  mixed  $users
94
     * @return $this
95
     */
96
    public function cc($users)
97
    {
98
        $this->cc = $users;
99
 
100
        return $this;
101
    }
102
 
103
    /**
104
     * Set the recipients of the message.
105
     *
106
     * @param  mixed  $users
107
     * @return $this
108
     */
109
    public function bcc($users)
110
    {
111
        $this->bcc = $users;
112
 
113
        return $this;
114
    }
115
 
116
    /**
117
     * Send a new mailable message instance.
118
     *
119
     * @param  \Illuminate\Contracts\Mail\Mailable  $mailable
120
     * @return \Illuminate\Mail\SentMessage|null
121
     */
122
    public function send(MailableContract $mailable)
123
    {
124
        return $this->mailer->send($this->fill($mailable));
125
    }
126
 
127
    /**
128
     * Push the given mailable onto the queue.
129
     *
130
     * @param  \Illuminate\Contracts\Mail\Mailable  $mailable
131
     * @return mixed
132
     */
133
    public function queue(MailableContract $mailable)
134
    {
135
        return $this->mailer->queue($this->fill($mailable));
136
    }
137
 
138
    /**
139
     * Deliver the queued message after (n) seconds.
140
     *
141
     * @param  \DateTimeInterface|\DateInterval|int  $delay
142
     * @param  \Illuminate\Contracts\Mail\Mailable  $mailable
143
     * @return mixed
144
     */
145
    public function later($delay, MailableContract $mailable)
146
    {
147
        return $this->mailer->later($delay, $this->fill($mailable));
148
    }
149
 
150
    /**
151
     * Populate the mailable with the addresses.
152
     *
153
     * @param  \Illuminate\Contracts\Mail\Mailable  $mailable
154
     * @return \Illuminate\Mail\Mailable
155
     */
156
    protected function fill(MailableContract $mailable)
157
    {
158
        return tap($mailable->to($this->to)
159
            ->cc($this->cc)
160
            ->bcc($this->bcc), function (MailableContract $mailable) {
161
                if ($this->locale) {
162
                    $mailable->locale($this->locale);
163
                }
164
            });
165
    }
166
}