Implement wildcard aliases
This commit is contained in:
parent
a01ddd9b22
commit
6400962a44
9 changed files with 141 additions and 25 deletions
|
|
@ -4,20 +4,34 @@ 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)
|
||||
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'] ?? '')),
|
||||
self::validateAliasAddress(trim($raw['alias_address'] ?? ''), $isWildcard),
|
||||
$isWildcard,
|
||||
self::validateInteger(trim($raw['wildcard_priority'] ?? '')),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -25,4 +39,14 @@ class AccountAddAliasData extends FormData
|
|||
{
|
||||
return $this->aliasAddress;
|
||||
}
|
||||
|
||||
public function isWildcard(): bool
|
||||
{
|
||||
return $this->isWildcard;
|
||||
}
|
||||
|
||||
public function getWildcardPriority(): int
|
||||
{
|
||||
return $this->wildcardPriority;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue