2021-09-16 22:09:15 +02:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace MailAccountAdmin\Frontend\Accounts;
|
|
|
|
|
|
|
|
|
|
use MailAccountAdmin\Common\FormData;
|
2022-01-02 03:05:40 +01:00
|
|
|
use MailAccountAdmin\Exceptions\InputValidationError;
|
2021-09-16 22:09:15 +02:00
|
|
|
|
|
|
|
|
class AccountAddAliasData extends FormData
|
|
|
|
|
{
|
|
|
|
|
private string $aliasAddress;
|
2022-01-02 03:05:40 +01:00
|
|
|
private bool $isWildcard;
|
|
|
|
|
private int $wildcardPriority;
|
2021-09-16 22:09:15 +02:00
|
|
|
|
2022-01-02 03:05:40 +01:00
|
|
|
private function __construct(string $aliasAddress, bool $isWildcard, int $wildcardPriority)
|
2021-09-16 22:09:15 +02:00
|
|
|
{
|
2022-01-02 03:05:40 +01:00
|
|
|
if ($isWildcard && $wildcardPriority === 0) {
|
|
|
|
|
throw new InputValidationError('Wildcard alias must have a wildcard priority other than 0.');
|
|
|
|
|
} elseif (!$isWildcard) {
|
|
|
|
|
$wildcardPriority = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 22:09:15 +02:00
|
|
|
$this->aliasAddress = $aliasAddress;
|
2022-01-02 03:05:40 +01:00
|
|
|
$this->isWildcard = $isWildcard;
|
|
|
|
|
$this->wildcardPriority = $wildcardPriority;
|
2021-09-16 22:09:15 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-22 22:30:13 +02:00
|
|
|
public static function createFromArray(array $raw): self
|
2021-09-16 22:09:15 +02:00
|
|
|
{
|
2022-01-02 03:05:40 +01:00
|
|
|
$isWildcard = self::validateBoolOption(trim($raw['is_wildcard'] ?? ''));
|
2021-09-16 22:09:15 +02:00
|
|
|
return new self(
|
2022-01-02 03:05:40 +01:00
|
|
|
self::validateAliasAddress(trim($raw['alias_address'] ?? ''), $isWildcard),
|
|
|
|
|
$isWildcard,
|
|
|
|
|
self::validateInteger(trim($raw['wildcard_priority'] ?? '')),
|
2021-09-16 22:09:15 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAliasAddress(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->aliasAddress;
|
|
|
|
|
}
|
2022-01-02 03:05:40 +01:00
|
|
|
|
|
|
|
|
public function isWildcard(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->isWildcard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getWildcardPriority(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->wildcardPriority;
|
|
|
|
|
}
|
2021-09-16 22:09:15 +02:00
|
|
|
}
|