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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Illuminate\Mail\Jobs;
use Closure;
use Illuminate\Support\Str;
use SuperClosure\Serializer;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Queue\SerializesAndRestoresModelIdentifiers;
class HandleQueuedMessage
{
use SerializesAndRestoresModelIdentifiers;
/**
* The name of the email view.
*
* @var string
*/
public $view;
/**
* The data to be passed to the view.
*
* @param array $data
*/
public $data;
/**
* The message configuration callback.
*
* @var \Closure
*/
public $callback;
/**
* Create a new job instance.
*
* @param string $view
* @param array $data
* @param \Closure $callback
* @return void
*/
public function __construct($view, $data, $callback)
{
$this->view = $view;
$this->data = $data;
$this->callback = $callback;
}
/**
* Handle the queued job.
*
* @param \Illuminate\Contracts\Mail\Mailer $mailer
* @return void
*/
public function handle(Mailer $mailer)
{
$mailer->send($this->view, $this->data, $this->callback);
}
/**
* Prepare the instance for serialization.
*
* @return array
*/
public function __sleep()
{
foreach ($this->data as $key => $value) {
$this->data[$key] = $this->getSerializedPropertyValue($value);
}
if ($this->callback instanceof Closure) {
$this->callback = (new Serializer)->serialize($this->callback);
}
return array_keys(get_object_vars($this));
}
/**
* Restore the model after serialization.
*
* @return void
*/
public function __wakeup()
{
foreach ($this->data as $key => $value) {
$this->data[$key] = $this->getRestoredPropertyValue($value);
}
if (Str::contains($this->callback, 'SerializableClosure')) {
$this->callback = (new Serializer)->unserialize($this->callback);
}
}
}