|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Slides\Connector\Auth\Clients\Mandrill; |
|
4
|
|
|
|
|
5
|
|
|
use Slides\Connector\Auth\Clients\Mandrill\Builders\Email; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Email |
|
9
|
|
|
* |
|
10
|
|
|
* @mixin Email |
|
11
|
|
|
* |
|
12
|
|
|
* @package Slides\Connector\Auth\Clients\Mandrill |
|
13
|
|
|
*/ |
|
14
|
|
|
class Mailer |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var Client |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $client; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $resolver; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Email constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param Client $client |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(Client $client) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->client = $client; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Set the Mandrill API token. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $secret |
|
40
|
|
|
* |
|
41
|
|
|
* @return static |
|
42
|
|
|
*/ |
|
43
|
|
|
public function setToken(string $secret) |
|
44
|
|
|
{ |
|
45
|
|
|
return new static(new Client([], [ |
|
46
|
|
|
'secretKey' => $secret |
|
47
|
|
|
])); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Set variable resolver instance. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $resolver |
|
54
|
|
|
* |
|
55
|
|
|
* @return static |
|
56
|
|
|
*/ |
|
57
|
|
|
public function setResolver(string $resolver) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->resolver = $resolver; |
|
60
|
|
|
|
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Begin the process of mailing a mail class instance. |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $template |
|
68
|
|
|
* |
|
69
|
|
|
* @return \Slides\Connector\Auth\Clients\Mandrill\Builders\Email |
|
70
|
|
|
*/ |
|
71
|
|
|
public function template(string $template) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->forward(__FUNCTION__, $template); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Begin the process of mailing a mail class instance. |
|
78
|
|
|
* |
|
79
|
|
|
* @param array $variables |
|
80
|
|
|
* |
|
81
|
|
|
* @return \Slides\Connector\Auth\Clients\Mandrill\Builders\Email |
|
82
|
|
|
*/ |
|
83
|
|
|
public function variables(array $variables) |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->forward(__FUNCTION__, $variables); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Begin the process of mailing a mail class instance. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $subject |
|
92
|
|
|
* |
|
93
|
|
|
* @return \Slides\Connector\Auth\Clients\Mandrill\Builders\Email |
|
94
|
|
|
*/ |
|
95
|
|
|
public function subject(string $subject) |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->forward(__FUNCTION__, $subject); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Begin the process of mailing a mail class instance. |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $email |
|
104
|
|
|
* @param string $name |
|
105
|
|
|
* |
|
106
|
|
|
* @return \Slides\Connector\Auth\Clients\Mandrill\Builders\Email |
|
107
|
|
|
*/ |
|
108
|
|
|
public function from(string $email, ?string $name = null) |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->forward(__FUNCTION__, $email, $name); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Begin the process of mailing a mail class instance. |
|
115
|
|
|
* |
|
116
|
|
|
* @param $recipients |
|
117
|
|
|
* |
|
118
|
|
|
* @return \Slides\Connector\Auth\Clients\Mandrill\Builders\Email |
|
119
|
|
|
*/ |
|
120
|
|
|
public function recipients($recipients) |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->forward(__FUNCTION__, $recipients); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Send the email. |
|
127
|
|
|
* |
|
128
|
|
|
* @param array $attributes |
|
129
|
|
|
* |
|
130
|
|
|
* @return mixed |
|
131
|
|
|
*/ |
|
132
|
|
|
public function send(array $attributes) |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->client->sendTemplate($attributes); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Forward call to email builder instance. |
|
139
|
|
|
* |
|
140
|
|
|
* @param string $method |
|
141
|
|
|
* @param mixed ...$arguments |
|
142
|
|
|
* |
|
143
|
|
|
* @return Email |
|
144
|
|
|
*/ |
|
145
|
|
|
protected function forward(string $method, ...$arguments) |
|
146
|
|
|
{ |
|
147
|
|
|
$builder = new Email($this, $this->resolver); |
|
148
|
|
|
|
|
149
|
|
|
if (!method_exists($builder, $method)) { |
|
150
|
|
|
throw new \BadMethodCallException('Method ' . $method . ' is not defined.'); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
return call_user_func([$builder, $method], ...$arguments); |
|
154
|
|
|
} |
|
155
|
|
|
} |