2
2
3
3
namespace Illuminate \Mail \Events ;
4
4
5
- use Symfony \Component \Mime \Email ;
5
+ use Exception ;
6
+ use Illuminate \Mail \SentMessage ;
6
7
8
+ /**
9
+ * @property \Symfony\Component\Mime\Email $message
10
+ */
7
11
class MessageSent
8
12
{
9
13
/**
10
- * The Symfony Email instance .
14
+ * The message that was sent .
11
15
*
12
- * @var \Symfony\Component\Mime\Email
16
+ * @var \Illuminate\Mail\SentMessage
13
17
*/
14
- public $ message ;
18
+ public $ sent ;
15
19
16
20
/**
17
21
* The message data.
@@ -23,14 +27,14 @@ class MessageSent
23
27
/**
24
28
* Create a new event instance.
25
29
*
26
- * @param \Symfony\Component\Mime\Email $message
30
+ * @param \Illuminate\Mail\SentMessage $message
27
31
* @param array $data
28
32
* @return void
29
33
*/
30
- public function __construct (Email $ message , array $ data = [])
34
+ public function __construct (SentMessage $ message , array $ data = [])
31
35
{
36
+ $ this ->sent = $ message ;
32
37
$ this ->data = $ data ;
33
- $ this ->message = $ message ;
34
38
}
35
39
36
40
/**
@@ -43,11 +47,11 @@ public function __serialize()
43
47
$ hasAttachments = collect ($ this ->message ->getAttachments ())->isNotEmpty ();
44
48
45
49
return $ hasAttachments ? [
46
- 'message ' => base64_encode (serialize ($ this ->message )),
50
+ 'sent ' => base64_encode (serialize ($ this ->sent )),
47
51
'data ' => base64_encode (serialize ($ this ->data )),
48
52
'hasAttachments ' => true ,
49
53
] : [
50
- 'message ' => $ this ->message ,
54
+ 'sent ' => $ this ->sent ,
51
55
'data ' => $ this ->data ,
52
56
'hasAttachments ' => false ,
53
57
];
@@ -62,11 +66,28 @@ public function __serialize()
62
66
public function __unserialize (array $ data )
63
67
{
64
68
if (isset ($ data ['hasAttachments ' ]) && $ data ['hasAttachments ' ] === true ) {
65
- $ this ->message = unserialize (base64_decode ($ data ['message ' ]));
69
+ $ this ->sent = unserialize (base64_decode ($ data ['sent ' ]));
66
70
$ this ->data = unserialize (base64_decode ($ data ['data ' ]));
67
71
} else {
68
- $ this ->message = $ data ['message ' ];
72
+ $ this ->sent = $ data ['sent ' ];
69
73
$ this ->data = $ data ['data ' ];
70
74
}
71
75
}
76
+
77
+ /**
78
+ * Dynamically get the original message.
79
+ *
80
+ * @param string $key
81
+ * @return mixed
82
+ *
83
+ * @throws \Exception
84
+ */
85
+ public function __get ($ key )
86
+ {
87
+ if ($ key === 'message ' ) {
88
+ return $ this ->sent ->getOriginalMessage ();
89
+ }
90
+
91
+ throw new Exception ('Unable to access undefined property on ' .__CLASS__ .': ' .$ key );
92
+ }
72
93
}
0 commit comments