generated from Nodarx/template
52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXM\ProviderImap\Client;
|
|
|
|
final class FetchTarget
|
|
{
|
|
private function __construct(
|
|
private readonly SequenceSet $sequenceSet,
|
|
private readonly IdentifierMode $identifierMode,
|
|
) {}
|
|
|
|
public static function all(IdentifierMode $identifierMode = IdentifierMode::Sequence): self
|
|
{
|
|
return new self(SequenceSet::all(), $identifierMode);
|
|
}
|
|
|
|
public static function sequence(int|string|SequenceSet $target): self
|
|
{
|
|
return new self(self::coerceSequenceSet($target), IdentifierMode::Sequence);
|
|
}
|
|
|
|
public static function uid(int|string|SequenceSet $target): self
|
|
{
|
|
return new self(self::coerceSequenceSet($target), IdentifierMode::Uid);
|
|
}
|
|
|
|
public function sequenceSet(): SequenceSet
|
|
{
|
|
return $this->sequenceSet;
|
|
}
|
|
|
|
public function identifierMode(): IdentifierMode
|
|
{
|
|
return $this->identifierMode;
|
|
}
|
|
|
|
public function toCommand(): string
|
|
{
|
|
return $this->identifierMode->toCommand();
|
|
}
|
|
|
|
private static function coerceSequenceSet(int|string|SequenceSet $target): SequenceSet
|
|
{
|
|
return match (true) {
|
|
$target instanceof SequenceSet => $target,
|
|
is_int($target) => SequenceSet::single($target),
|
|
default => SequenceSet::parse($target),
|
|
};
|
|
}
|
|
} |