8000 Add Wrapper for Symfony SentMessage (#38803) · laravel/framework@c8d1654 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8d1654

Browse files
Jubekidriesvints
andauthored
Add Wrapper for Symfony SentMessage (#38803)
* Create SentMessage wrapper for Symfony's SentMessage * Wrap Symfony SentMessage * Update Docblocks to Illuminate\Mail\SentMessage * Fix sendMailable * Update SentMessage.php Co-authored-by: Dries Vints <dries@vints.io>
1 parent e23e57e commit c8d1654

File tree

4 files changed

+65
-11
lines changed

4 files changed

+65
-11
lines changed

src/Illuminate/Mail/Mailable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Mailable implements MailableContract, Renderable
167167
* Send the message using the given mailer.
168168
*
169169
* @param \Illuminate\Contracts\Mail\Factory|\Illuminate\Contracts\Mail\Mailer $mailer
170-
* @return \Symfony\Component\Mailer\SentMessage|null
170+
* @return \Illuminate\Mail\SentMessage|null
171171
*/
172172
public function send($mailer)
173173
{

src/Illuminate/Mail/Mailer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function bcc($users)
188188
*
189189
* @param string $html
190190
* @param mixed $callback
191-
* @return \Symfony\Component\Mailer\SentMessage|null
191+
* @return \Illuminate\Mail\SentMessage|null
192192
*/
193193
public function html($html, $callback)
194194
{
@@ -200,7 +200,7 @@ public function html($html, $callback)
200200
*
201201
* @param string $text
202202
* @param mixed $callback
203-
* @return \Symfony\Component\Mailer\SentMessage|null
203+
* @return \Illuminate\Mail\SentMessage|null
204204
*/
205205
public function raw($text, $callback)
206206
{
@@ -213,7 +213,7 @@ public function raw($text, $callback)
213213
* @param string $view
214214
* @param array $data
215215
* @param mixed $callback
216-
* @return \Symfony\Component\Mailer\SentMessage|null
216+
* @return \Illuminate\Mail\SentMessage|null
217217
*/
218218
public function plain($view, array $data, $callback)
219219
{
@@ -245,7 +245,7 @@ public function render($view, array $data = [])
245245
* @param \Illuminate\Contracts\Mail\Mailable|string|array $view
246246
* @param array $data
247247
* @param \Closure|string|null $callback
248-
* @return \Symfony\Component\Mailer\SentMessage|null
248+
* @return \Illuminate\Mail\SentMessage|null
249249
*/
250250
public function send($view, array $data = [], $callback = null)
251251
{
@@ -286,15 +286,15 @@ public function send($view, array $data = [], $callback = null)
286286

287287
$this->dispatchSentEvent($message, $data);
288288

289-
return $sentMessage;
289+
return $sentMessage === null ? null : new SentMessage($sentMessage);
290290
}
291291
}
292292

293293
/**
294294
* Send the given mailable.
295295
*
296296
* @param \Illuminate\Contracts\Mail\Mailable $mailable
297-
* @return mixed
297+
* @return \Illuminate\Mail\SentMessage|null
298298
*/
299299
protected function sendMailable(MailableContract $mailable)
300300
{

src/Illuminate/Mail/SentMessage.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Illuminate\Mail;
4+
5+
use Illuminate\Support\Traits\ForwardsCalls;
6+
use Symfony\Component\Mailer\SentMessage as SymfonySentMessage;
7+
8+
/**
9+
* @mixin \Symfony\Component\Mailer\SentMessage
10+
*/
11+
class SentMessage
12+
{
13+
use ForwardsCalls;
14+
15+
/**
16+
* The Symfony SentMessage instance.
17+
*
18+
* @var \Symfony\Component\Mailer\SentMessage
19+
*/
20+
protected $sentMessage;
21+
22+
/**
23+
* Create a new SentMessage instance.
24+
*
25+
* @param \Symfony\Component\Mailer\SentMessage $sentMessage
26+
* @return void
27+
*/
28+
public function __construct(SymfonySentMessage $sentMessage)
29+
{
30+
$this->sentMessage = $sentMessage;
31+
}
32+
33+
/**
34+
* Get the underlying Symfony Email instance.
35+
*
36+
* @return \Symfony\Component\Mailer\SentMessage
37+
*/
38+
public function getSymfonySentMessage()
39+
{
40+
return $this->sentMessage;
41+
}
42+
43+
/**
44+
* Dynamically pass missing methods to the Symfony instance.
45+
*
46+
* @param string $method
47+
* @param array $parameters
48+
* @return mixed
49+
*/
50+
public function __call($method, $parameters)
51+
{
52+
return $this->forwardCallTo($this->sentMessage, $method, $parameters);
53+
}
54+
}

src/Illuminate/Support/Facades/Mail.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
* @method static \Illuminate\Mail\PendingMail to($users)
1111
* @method static \Illuminate\Support\Collection queued(string $mailable, \Closure|string $callback = null)
1212
* @method static \Illuminate\Support\Collection sent(string $mailable, \Closure|string $callback = null)
13-
* @method static \Symfony\Component\Mailer\SentMessage|null raw(string $text, $callback)
14-
* @method static \Symfony\Component\Mailer\SentMessage|null plain(string $view, array $data, $callback)
15-
* @method static \Symfony\Component\Mailer\SentMessage|null html(string $html, $callback)
16-
* @method static \Symfony\Component\Mailer\SentMessage|null send(\Illuminate\Contracts\Mail\Mailable|string|array $view, array $data = [], \Closure|string $callback = null)
13+
* @method static \Illuminate\Mail\SentMessage|null raw(string $text, $callback)
14+
* @method static \Illuminate\Mail\SentMessage|null plain(string $view, array $data, $callback)
15+
* @method static \Illuminate\Mail\SentMessage|null html(string $html, $callback)
16+
* @method static \Illuminate\Mail\SentMessage|null send(\Illuminate\Contracts\Mail\Mailable|string|array $view, array $data = [], \Closure|string $callback = null)
1717
* @method static array failures()
1818
* @method static bool hasQueued(string $mailable)
1919
* @method static bool hasSent(string $mailable)

0 commit comments

Comments
 (0)
0