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
+6 -7
View File
@@ -22,17 +22,16 @@ final readonly class PreviewSource
string $mimeType,
public ?int $size,
public Closure $resourceFactory,
public ?string $selector = null,
) {
if ($this->sourceType === '' || $this->identity === '' || $this->signature === '') {
throw new InvalidArgumentException('Preview sources require a type, identity, and content signature');
if (preg_match('/^[a-z][a-z0-9-]*$/', $this->sourceType) !== 1) {
throw new InvalidArgumentException('Preview source type must use lowercase letters, numbers, and hyphens');
}
if ($this->identity === '' || $this->signature === '') {
throw new InvalidArgumentException('Preview sources require an identity and content signature');
}
if ($this->size !== null && $this->size < 0) {
throw new InvalidArgumentException('Preview source size cannot be negative');
}
if ($this->selector === '') {
throw new InvalidArgumentException('Preview source selectors must be null or non-empty');
}
$this->mimeType = MimeType::normalize($mimeType);
}
@@ -40,7 +39,7 @@ final readonly class PreviewSource
{
$resource = ($this->resourceFactory)();
if (!$resource instanceof BinaryResource) {
throw new PreviewException('Preview source factory did not return a BinaryResource');
throw new PreviewGenerationException('Preview source factory did not return a BinaryResource');
}
return $resource;
}