53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace MailAccountAdmin\Frontend\Accounts;
|
|
|
|
use MailAccountAdmin\Common\FormData;
|
|
use MailAccountAdmin\Exceptions\InputValidationError;
|
|
|
|
class AccountAddAliasData extends FormData
|
|
{
|
|
private string $aliasAddress;
|
|
private bool $isWildcard;
|
|
private int $wildcardPriority;
|
|
|
|
private function __construct(string $aliasAddress, bool $isWildcard, int $wildcardPriority)
|
|
{
|
|
if ($isWildcard && $wildcardPriority === 0) {
|
|
throw new InputValidationError('Wildcard alias must have a wildcard priority other than 0.');
|
|
} elseif (!$isWildcard) {
|
|
$wildcardPriority = 0;
|
|
}
|
|
|
|
$this->aliasAddress = $aliasAddress;
|
|
$this->isWildcard = $isWildcard;
|
|
$this->wildcardPriority = $wildcardPriority;
|
|
}
|
|
|
|
public static function createFromArray(array $raw): self
|
|
{
|
|
$isWildcard = self::validateBoolOption(trim($raw['is_wildcard'] ?? ''));
|
|
return new self(
|
|
self::validateAliasAddress(trim($raw['alias_address'] ?? ''), $isWildcard),
|
|
$isWildcard,
|
|
self::validateInteger(trim($raw['wildcard_priority'] ?? '')),
|
|
);
|
|
}
|
|
|
|
public function getAliasAddress(): string
|
|
{
|
|
return $this->aliasAddress;
|
|
}
|
|
|
|
public function isWildcard(): bool
|
|
{
|
|
return $this->isWildcard;
|
|
}
|
|
|
|
public function getWildcardPriority(): int
|
|
{
|
|
return $this->wildcardPriority;
|
|
}
|
|
}
|