feat: implement preview manager

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-29 18:42:30 -04:00
parent eaea5f4c83
commit f39ad1804d
13 changed files with 676 additions and 175 deletions
+3 -28
View File
@@ -11,47 +11,22 @@ final readonly class PreviewRequest
public string $preferredMimeType;
public function __construct(
public string $variant,
public int $maxWidth,
public int $maxHeight,
string $preferredMimeType,
public int $quality,
public ?int $page = null,
public ?float $timestamp = null,
public int $maxSourceSize = 26214400,
) {
if (preg_match('/^[a-z][a-z0-9-]*$/', $this->variant) !== 1) {
throw new InvalidArgumentException('Preview variant must use lowercase letters, numbers, and hyphens');
}
if ($this->maxWidth < 1 || $this->maxHeight < 1) {
throw new InvalidArgumentException('Preview dimensions must be positive');
}
if ($this->quality < 1 || $this->quality > 100) {
throw new InvalidArgumentException('Preview quality must be between 1 and 100');
}
if ($this->page !== null && $this->page < 1) {
throw new InvalidArgumentException('Preview page numbers start at 1');
}
if ($this->timestamp !== null && $this->timestamp < 0) {
throw new InvalidArgumentException('Preview timestamps cannot be negative');
if ($this->maxSourceSize < 1) {
throw new InvalidArgumentException('Preview maximum source size must be positive');
}
$this->preferredMimeType = MimeType::normalize($preferredMimeType);
}
/**
* Fixed-order scalar representation for cache-key generation.
*
* @return array{variant:string,maxWidth:int,maxHeight:int,preferredMimeType:string,quality:int,page:?int,timestamp:?float}
*/
public function normalized(): array
{
return [
'variant' => $this->variant,
'maxWidth' => $this->maxWidth,
'maxHeight' => $this->maxHeight,
'preferredMimeType' => $this->preferredMimeType,
'quality' => $this->quality,
'page' => $this->page,
'timestamp' => $this->timestamp,
];
}
}