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