Initial xentral_oss_20.3.c9ffacf

This commit is contained in:
Alex
2021-05-21 08:49:41 +02:00
parent 5406e4a551
commit 34e5ac43d9
18884 changed files with 2109867 additions and 0 deletions
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Xentral\Components\Mailer\Config;
abstract class AbstractMailerConfig implements MailerConfigInterface
{
/** @var array $data */
protected $data;
/**
* @param array $data
*/
public function __construct($data = [])
{
$this->data = $data;
}
/**
* @inheritDoc
*/
public function getConfigValue(string $key, $default = null)
{
if (array_key_exists($key, $this->data)) {
return $this->data[$key];
}
return $default;
}
/**
* @inheritDoc
*/
public function getValues(): array
{
return $this->data;
}
}
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Xentral\Components\Mailer\Config;
use Xentral\Components\Mailer\Exception\MailerConfigException;
interface MailerConfigInterface
{
/**
* @param string $key
* @param mixed $default
*
* @return mixed|null @todo: try to use type annotation
*/
public function getConfigValue(string $key, $default = null);
/**
* @throws MailerConfigException
*
* @return void
*/
public function validate(): void;
/**
* @return array
*/
public function getValues(): array;
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Xentral\Components\Mailer\Config;
use PHPMailer\PHPMailer\PHPMailer;
use Xentral\Components\Mailer\Exception\MailerConfigException;
final class OAuthMailerConfig 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('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,
'auth_type' => 'XOAUTH2',
];
}
}
@@ -0,0 +1,71 @@
<?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,
];
}
}