mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-26 14:40:29 +01:00
72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Xentral\Components\Mailer\Config;
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use Xentral\Components\Mailer\Exception\MailerConfigException;
|
|
|
|
final class SmtpMailerConfig extends AbstractMailerConfig
|
|
{
|
|
/**
|
|
* @param array $data
|
|
*/
|
|
public function __construct($data = [])
|
|
{
|
|
parent::__construct($this->getDefaults());
|
|
foreach ($data as $key => $value) {
|
|
$this->data[$key] = $value;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function validate(): void
|
|
{
|
|
if (!array_key_exists('sender_email', $this->data) || $this->data['sender_email'] === '') {
|
|
throw new MailerConfigException('Key "sender_email" is required!');
|
|
}
|
|
if (!array_key_exists('host', $this->data) || $this->data['host'] === '') {
|
|
throw new MailerConfigException('Key "host" is required!');
|
|
}
|
|
if (!array_key_exists('username', $this->data) || $this->data['username'] === '') {
|
|
throw new MailerConfigException('Key "username" is required!');
|
|
}
|
|
if (!array_key_exists('password', $this->data) || $this->data['password'] === '') {
|
|
throw new MailerConfigException('Key "password" is required!');
|
|
}
|
|
if (!array_key_exists('smtp_security', $this->data)) {
|
|
throw new MailerConfigException('Key "smtp_security" is required!');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
private function getDefaults(): array
|
|
{
|
|
return [
|
|
'priority' => 3,
|
|
'charset' => PHPMailer::CHARSET_UTF8,
|
|
'contenttype' => 'text/html',
|
|
'encoding' => '8bit',
|
|
'sender_name' => '',
|
|
'wordwrap' => 0,
|
|
'mailer' => 'smtp',
|
|
'hostname' => '',
|
|
'port' => 25,
|
|
'helo' => '',
|
|
'timeout' => 30,
|
|
'singleto' => false,
|
|
'sendmail' => '/usr/sbin/sendmail',
|
|
'smtp_enabled' => true,
|
|
'smtp_autotls_enabled' => false,
|
|
'smtp_options' => [],
|
|
'smtp_debug' => 0,
|
|
'smtp_keepalive' => false,
|
|
];
|
|
}
|
|
}
|