1
|
|
<?php
|
2
|
|
/**
|
3
|
|
* This file is part of the Shieldon package.
|
4
|
|
*
|
5
|
|
* (c) Terry L. <contact@terryl.in>
|
6
|
|
*
|
7
|
|
* For the full copyright and license information, please view the LICENSE
|
8
|
|
* file that was distributed with this source code.
|
9
|
|
*
|
10
|
|
* php version 7.1.0
|
11
|
|
*
|
12
|
|
* @category Web-security
|
13
|
|
* @package Shieldon
|
14
|
|
* @author Terry Lin <contact@terryl.in>
|
15
|
|
* @copyright 2019 terrylinooo
|
16
|
|
* @license https://github.com/terrylinooo/shieldon/blob/2.x/LICENSE MIT
|
17
|
|
* @link https://github.com/terrylinooo/shieldon
|
18
|
|
* @see https://shieldon.io
|
19
|
|
*/
|
20
|
|
|
21
|
|
declare(strict_types=1);
|
22
|
|
|
23
|
|
namespace Shieldon\Firewall\Firewall\Messenger;
|
24
|
|
|
25
|
|
use Shieldon\Messenger\Messenger\MessengerInterface;
|
26
|
|
use Shieldon\Messenger\Smtp;
|
27
|
|
use function Shieldon\Firewall\__;
|
28
|
|
|
29
|
|
/**
|
30
|
|
* The get for SMTP.
|
31
|
|
*/
|
32
|
|
class ItemSmtp
|
33
|
|
{
|
34
|
|
/**
|
35
|
|
* Initialize and get the instance.
|
36
|
|
*
|
37
|
|
* @param array $setting The configuration of that messanger.
|
38
|
|
*
|
39
|
|
* @return MessengerInterface
|
40
|
|
*/
|
41
|
3
|
public static function get(array $setting): MessengerInterface
|
42
|
|
{
|
43
|
3
|
$sender = $setting['config']['sender'] ?? '';
|
44
|
3
|
$recipients = $setting['config']['recipients'] ?? [];
|
45
|
3
|
$host = $setting['config']['host'] ?? '';
|
46
|
3
|
$user = $setting['config']['user'] ?? '';
|
47
|
3
|
$pass = $setting['config']['pass'] ?? '';
|
48
|
3
|
$port = $setting['config']['port'] ?? '';
|
49
|
|
|
50
|
3
|
$instance = new Smtp($user, $pass, $host, (int) $port);
|
51
|
3
|
$instance->setSubject(__('core', 'messenger_text_mail_subject'));
|
52
|
3
|
$instance->addSender($sender);
|
53
|
|
|
54
|
3
|
foreach ($recipients as $recipient) {
|
55
|
3
|
$instance->addRecipient($recipient);
|
56
|
|
}
|
57
|
|
|
58
|
3
|
return $instance;
|
59
|
|
}
|
60
|
|
}
|