1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DansMaCulotte\MailTemplate\Drivers; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use GuzzleHttp\Client; |
7
|
|
|
use SendinBlue\Client\Api\SMTPApi; |
8
|
|
|
use SendinBlue\Client\Configuration; |
9
|
|
|
use SendinBlue\Client\Model\SendSmtpEmail; |
10
|
|
|
use SendinBlue\Client\Model\SendSmtpEmailSender; |
11
|
|
|
use SendinBlue\Client\Model\SendSmtpEmailTo; |
12
|
|
|
|
13
|
|
|
class SendinblueDriver implements Driver |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** @var SMTPApi|null */ |
17
|
|
|
public $client = null; |
18
|
|
|
|
19
|
|
|
/** @var array */ |
20
|
|
|
public $body = []; |
21
|
|
|
|
22
|
|
|
/** @var array */ |
23
|
|
|
public $message = []; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Driver constructor. |
29
|
|
|
* @param array $config |
30
|
|
|
*/ |
31
|
|
|
public function __construct(array $config) |
32
|
|
|
{ |
33
|
|
|
$config = Configuration::getDefaultConfiguration()->setApiKey('api-key', $config['key']); |
34
|
|
|
$this->client = new SMTPApi(new Client(), $config, null); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $name |
39
|
|
|
* @param string $email |
40
|
|
|
* @return Driver |
41
|
|
|
*/ |
42
|
|
|
public function setFrom(string $name, string $email): Driver |
43
|
|
|
{ |
44
|
|
|
$this->message['sender'] = new SendSmtpEmailSender([ |
45
|
|
|
'name' => $name, |
46
|
|
|
'email' => $email |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $template |
54
|
|
|
* @return Driver |
55
|
|
|
*/ |
56
|
|
|
public function setTemplate($template): Driver |
57
|
|
|
{ |
58
|
|
|
$this->message['templateId'] = $template; |
59
|
|
|
|
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $subject |
65
|
|
|
* @return Driver |
66
|
|
|
*/ |
67
|
|
|
public function setSubject(string $subject): Driver |
68
|
|
|
{ |
69
|
|
|
$this->message['subject'] = $subject; |
70
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $name |
76
|
|
|
* @param string $email |
77
|
|
|
* @return Driver |
78
|
|
|
*/ |
79
|
|
|
public function setRecipient(string $name, string $email): Driver |
80
|
|
|
{ |
81
|
|
|
$this->message['to'] = [new SendSmtpEmailTo([ |
82
|
|
|
'name' => $name, |
83
|
|
|
'email' => $email |
84
|
|
|
])]; |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param array $variables |
91
|
|
|
* @return Driver |
92
|
|
|
*/ |
93
|
|
|
public function setVariables(array $variables): Driver |
94
|
|
|
{ |
95
|
|
|
|
96
|
|
|
$params = []; |
97
|
|
|
foreach ($variables as $variableKey => $variableValue) { |
98
|
|
|
$params[$variableKey] = $variableValue; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$this->message['params'] = $params; |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param string $language |
108
|
|
|
* @return Driver |
109
|
|
|
*/ |
110
|
|
|
public function setLanguage(string $language): Driver |
111
|
|
|
{ |
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return array |
117
|
|
|
* @throws \SendinBlue\Client\ApiException |
118
|
|
|
*/ |
119
|
|
|
public function send(): array |
120
|
|
|
{ |
121
|
|
|
$email = new SendSmtpEmail($this->message); |
122
|
|
|
$response = $this->client->sendTransacEmail($email); |
|
|
|
|
123
|
|
|
return ['messageId' => $response->getMessageId()]; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return array |
128
|
|
|
*/ |
129
|
|
|
public function toArray(): array |
130
|
|
|
{ |
131
|
|
|
return [ |
132
|
|
|
'body' => array_merge($this->body, [ |
133
|
|
|
'Messages' => [ |
134
|
|
|
$this->message, |
135
|
|
|
], |
136
|
|
|
]) |
137
|
|
|
]; |
138
|
|
|
} |
139
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.