MessageSent.php
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Illuminate\Mail\Events;
use Swift_Attachment;
class MessageSent
{
/**
* The Swift message instance.
*
* @var \Swift_Message
*/
public $message;
/**
* The message data.
*
* @var array
*/
public $data;
/**
* Create a new event instance.
*
* @param \Swift_Message $message
* @param array $data
* @return void
*/
public function __construct($message, $data = [])
{
$this->data = $data;
$this->message = $message;
}
/**
* Get the serializable representation of the object.
*
* @return array
*/
public function __serialize()
{
$hasAttachments = collect($this->message->getChildren())
->whereInstanceOf(Swift_Attachment::class)
->isNotEmpty();
return $hasAttachments ? [
'message' => base64_encode(serialize($this->message)),
'data' => base64_encode(serialize($this->data)),
'hasAttachments' => true,
] : [
'message' => $this->message,
'data' => $this->data,
'hasAttachments' => false,
];
}
/**
* Marshal the object from its serialized data.
*
* @param array $data
* @return void
*/
public function __unserialize(array $data)
{
if (isset($data['hasAttachments']) && $data['hasAttachments'] === true) {
$this->message = unserialize(base64_decode($data['message']));
$this->data = unserialize(base64_decode($data['data']));
} else {
$this->message = $data['message'];
$this->data = $data['data'];
}
}
}