|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Mail as MailModel; |
|
6
|
|
|
use Illuminate\Support\Facades\Config; |
|
7
|
|
|
use Illuminate\Support\Facades\Mail as MailFacade; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Mail |
|
11
|
|
|
* @package App\Helpers |
|
12
|
|
|
*/ |
|
13
|
|
|
class Mail |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Stored Mail Model |
|
17
|
|
|
* |
|
18
|
|
|
* @var MailModel|null |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $mailModel = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Quick Way to get Cached MailModel |
|
24
|
|
|
* |
|
25
|
|
|
* @return MailModel|null |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getMail() |
|
28
|
|
|
{ |
|
29
|
|
|
return self::getInstance()->get(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Return cached Mail Model |
|
34
|
|
|
* |
|
35
|
|
|
* @return MailModel|null |
|
36
|
|
|
*/ |
|
37
|
|
|
public function get() |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->mailModel; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Create and return a Mail instance |
|
44
|
|
|
* |
|
45
|
|
|
* @return Mail |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function getInstance() |
|
48
|
|
|
{ |
|
49
|
|
|
static $instance = null; |
|
50
|
|
|
|
|
51
|
|
|
if ($instance === null) { |
|
52
|
|
|
$instance = new static(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $instance; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Send an Email |
|
60
|
|
|
* |
|
61
|
|
|
* @param array $configuration |
|
62
|
|
|
* @param string $view |
|
63
|
|
|
*/ |
|
64
|
|
|
public function send(array $configuration, string $view = 'habbo-web-mail.confirm-mail') |
|
65
|
|
|
{ |
|
66
|
|
|
if (Config::get('mail.enable') == false) |
|
67
|
|
|
return; |
|
68
|
|
|
|
|
69
|
|
|
MailFacade::send($view, $configuration, function ($message) use ($configuration) { |
|
70
|
|
|
$message->from(Config::get('mail.from.address'), Config::get('mail.from.name')); |
|
71
|
|
|
$message->to($configuration['email'])->subject($configuration['subject']); |
|
72
|
|
|
}); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Store an E-mail |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $email |
|
79
|
|
|
* @param string $url |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
public function store(string $email, string $url): string |
|
83
|
|
|
{ |
|
84
|
|
|
(new MailModel)->store($token = uniqid('HabboMail', true), $url, $email)->save(); |
|
85
|
|
|
|
|
86
|
|
|
return $token; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Update Mail Model Data |
|
91
|
|
|
* |
|
92
|
|
|
* @param string $token |
|
93
|
|
|
* @param array $parameters |
|
94
|
|
|
* @return MailModel |
|
95
|
|
|
*/ |
|
96
|
|
|
public function update(string $token, array $parameters) |
|
97
|
|
|
{ |
|
98
|
|
|
$mail = $this->get($token); |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
$mail->update($parameters); |
|
101
|
|
|
|
|
102
|
|
|
return $mail; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Return if Exists E-Mail with that Token |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $token |
|
109
|
|
|
* @return bool |
|
110
|
|
|
*/ |
|
111
|
|
|
public function has(string $token) |
|
112
|
|
|
{ |
|
113
|
|
|
return Mail::getInstance()->getByToken($token) !== null; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Get an E-mail by Token |
|
118
|
|
|
* |
|
119
|
|
|
* @param string $token |
|
120
|
|
|
* @return MailModel |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getByToken(string $token) |
|
123
|
|
|
{ |
|
124
|
|
|
$mailRequest = MailModel::where('token', $token)->where('used', '0')->first(); |
|
125
|
|
|
|
|
126
|
|
|
$mailRequest->update(['used' => '1']); |
|
127
|
|
|
|
|
128
|
|
|
return $this->set($mailRequest); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Set Mail Model in Cache |
|
133
|
|
|
* |
|
134
|
|
|
* @param MailModel $model |
|
135
|
|
|
* @return MailModel |
|
136
|
|
|
*/ |
|
137
|
|
|
public function set(MailModel $model) |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->mailModel = $model; |
|
140
|
|
|
} |
|
141
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.