1
|
|
|
<?php namespace nyx\notify\transports\mail; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Mail Driver Manager |
5
|
|
|
* |
6
|
|
|
* @package Nyx\Notify |
7
|
|
|
* @version 0.1.0 |
8
|
|
|
* @author Michal Chojnacki <[email protected]> |
9
|
|
|
* @copyright 2012-2017 Nyx Dev Team |
10
|
|
|
* @link https://github.com/unyx/nyx |
11
|
|
|
*/ |
12
|
|
|
class DriverManager extends \Illuminate\Support\Manager |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Creates a Mail() Mail Driver. |
16
|
|
|
* |
17
|
|
|
* @return drivers\Mail |
18
|
|
|
*/ |
19
|
|
|
protected function createMailDriver() : drivers\Mail |
20
|
|
|
{ |
21
|
|
|
return new drivers\Mail; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Creates a SMTP Mail Driver. |
26
|
|
|
* |
27
|
|
|
* @return drivers\Smtp |
28
|
|
|
*/ |
29
|
|
|
protected function createSmtpDriver() : drivers\Smtp |
30
|
|
|
{ |
31
|
|
|
$config = $this->app->make('config')->get('mail.smtp'); |
32
|
|
|
$driver = new drivers\Smtp($config['host'], $config['port'], $config['encryption'] ?? null); |
33
|
|
|
|
34
|
|
|
if (isset($config['username'])) { |
35
|
|
|
$driver->setUsername($config['username']); |
36
|
|
|
$driver->setPassword($config['password']); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if (isset($config['stream'])) { |
40
|
|
|
$driver->setStreamOptions($config['stream']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $driver; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Creates a Sendmail Mail Driver. |
48
|
|
|
* |
49
|
|
|
* @return drivers\Sendmail |
50
|
|
|
*/ |
51
|
|
|
protected function createSendmailDriver() : drivers\Sendmail |
52
|
|
|
{ |
53
|
|
|
return new drivers\Sendmail($this->app->make('config')->get('mail.sendmail')); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Creates a Mailgun Mail Driver. |
58
|
|
|
* |
59
|
|
|
* @return drivers\Mailgun |
60
|
|
|
*/ |
61
|
|
|
protected function createMailgunDriver() : drivers\Mailgun |
62
|
|
|
{ |
63
|
|
|
$config = $this->app->make('config')->get('services.mailgun', []); |
64
|
|
|
|
65
|
|
|
return new drivers\Mailgun($this->createHttpClient($config), $config['secret'], $config['domain']); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Creates a Mandrill Mail Driver. |
70
|
|
|
* |
71
|
|
|
* @return drivers\Mandrill |
72
|
|
|
*/ |
73
|
|
|
protected function createMandrillDriver() : drivers\Mandrill |
74
|
|
|
{ |
75
|
|
|
$config = $this->app->make('config')->get('services.mandrill', []); |
76
|
|
|
|
77
|
|
|
return new drivers\Mandrill($this->createHttpClient($config), $config['secret']); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Creates a Postmark Mail Driver. |
82
|
|
|
* |
83
|
|
|
* @return drivers\Postmark |
84
|
|
|
*/ |
85
|
|
|
protected function createPostmarkDriver() : drivers\Postmark |
86
|
|
|
{ |
87
|
|
|
$config = $this->app->make('config')->get('services.postmark', []); |
88
|
|
|
|
89
|
|
|
return new drivers\Postmark($this->createHttpClient($config), $config['secret']); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Creates a SparkPost Mail Driver. |
94
|
|
|
* |
95
|
|
|
* @return drivers\SparkPost |
96
|
|
|
*/ |
97
|
|
|
protected function createSparkPostDriver() : drivers\SparkPost |
98
|
|
|
{ |
99
|
|
|
$config = $this->app->make('config')->get('services.sparkpost', []); |
100
|
|
|
|
101
|
|
|
return new drivers\SparkPost($this->createHttpClient($config), $config['secret'], $config['options'] ?? []); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Creates a Sendgrid Mail Driver. |
106
|
|
|
* |
107
|
|
|
* @return drivers\Sendgrid |
108
|
|
|
*/ |
109
|
|
|
protected function createSendgridDriver() : drivers\Sendgrid |
110
|
|
|
{ |
111
|
|
|
$config = $this->app->make('config')->get('services.sendgrid', []); |
112
|
|
|
|
113
|
|
|
return new drivers\Sendgrid($this->createHttpClient($config), $config['secret']); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Creates a Log Mail Driver. |
118
|
|
|
* |
119
|
|
|
* @return drivers\Log |
120
|
|
|
*/ |
121
|
|
|
protected function createLogDriver() : drivers\Log |
122
|
|
|
{ |
123
|
|
|
return new drivers\Log($this->app->make('Psr\Log\LoggerInterface')); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritDoc} |
128
|
|
|
*/ |
129
|
|
|
public function getDefaultDriver() |
130
|
|
|
{ |
131
|
|
|
return $this->app->make('config')->get('mail.driver'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Creates a new HTTP Client instance. |
136
|
|
|
* |
137
|
|
|
* @param array $config The Client's configuration options. |
138
|
|
|
* @return \GuzzleHttp\ClientInterface The created HTTP Client. |
139
|
|
|
*/ |
140
|
|
|
protected function createHttpClient(array $config) : \GuzzleHttp\ClientInterface |
141
|
|
|
{ |
142
|
|
|
$config = $config['http'] ?? []; |
143
|
|
|
$config['connect_timeout'] = $config['connect_timeout'] ?? 60; |
144
|
|
|
|
145
|
|
|
return new \GuzzleHttp\Client($config); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|