|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Quantum PHP Framework |
|
5
|
|
|
* |
|
6
|
|
|
* An open source software development framework for PHP |
|
7
|
|
|
* |
|
8
|
|
|
* @package Quantum |
|
9
|
|
|
* @author Arman Ag. <[email protected]> |
|
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
|
11
|
|
|
* @link http://quantum.softberg.org/ |
|
12
|
|
|
* @since 2.9.5 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Quantum\Libraries\Mailer; |
|
16
|
|
|
|
|
17
|
|
|
use Quantum\Libraries\Mailer\Exceptions\MailerException; |
|
18
|
|
|
use Quantum\Libraries\Mailer\Contracts\MailerInterface; |
|
19
|
|
|
use Quantum\Exceptions\BaseException; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class Mailer |
|
23
|
|
|
* @package Quantum\Libraries\Mailer |
|
24
|
|
|
* @method MailerInterface setFrom(string $email, ?string $name = null) |
|
25
|
|
|
* @method array getFrom() |
|
26
|
|
|
* @method MailerInterface setAddress(string $email, ?string $name = null) |
|
27
|
|
|
* @method array getAddresses() |
|
28
|
|
|
* @method MailerInterface setSubject(?string $subject) |
|
29
|
|
|
* @method string|null getSubject() |
|
30
|
|
|
* @method MailerInterface setTemplate(string $templatePath) |
|
31
|
|
|
* @method string|null getTemplate() |
|
32
|
|
|
* @method MailerInterface setBody($message) |
|
33
|
|
|
* @method string|array getBody() |
|
34
|
|
|
* @method bool send() |
|
35
|
|
|
*/ |
|
36
|
|
|
class Mailer |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* SMTP adapter |
|
41
|
|
|
*/ |
|
42
|
|
|
const SMTP = 'smtp'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Mailgun adapter |
|
46
|
|
|
*/ |
|
47
|
|
|
const MAILGUN = 'mailgun'; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Mandrill adapter |
|
51
|
|
|
*/ |
|
52
|
|
|
const MANDRILL = 'mandrill'; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Sendgrid adapter |
|
56
|
|
|
*/ |
|
57
|
|
|
const SENDGRID = 'sendgrid'; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Sendinblue adapter |
|
61
|
|
|
*/ |
|
62
|
|
|
const SENDINBLUE = 'sendinblue'; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var MailerInterface |
|
66
|
|
|
*/ |
|
67
|
|
|
private $adapter; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param MailerInterface $adapter |
|
71
|
|
|
*/ |
|
72
|
|
|
public function __construct(MailerInterface $adapter) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->adapter = $adapter; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return MailerInterface |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getAdapter(): MailerInterface |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->adapter; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param string $method |
|
87
|
|
|
* @param array|null $arguments |
|
88
|
|
|
* @return mixed |
|
89
|
|
|
* @throws BaseException |
|
90
|
|
|
*/ |
|
91
|
|
|
public function __call(string $method, ?array $arguments) |
|
92
|
|
|
{ |
|
93
|
|
|
if (!method_exists($this->adapter, $method)) { |
|
94
|
|
|
throw MailerException::methodNotSupported($method, get_class($this->adapter)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $this->adapter->$method(...$arguments); |
|
98
|
|
|
} |
|
99
|
|
|
} |