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
+7 -8
View File
@@ -11,12 +11,11 @@ final class TenantPreview extends JsonSerializableObject
{
protected bool $enabled = true;
protected string $store = 'previews';
protected TenantPreviewGeneration $generation;
protected int $maxSourceSize = 26214400;
protected TenantPreviewVariants $variants;
public function __construct()
{
$this->generation = new TenantPreviewGeneration();
$this->variants = new TenantPreviewVariants();
}
@@ -40,11 +39,11 @@ final class TenantPreview extends JsonSerializableObject
$this->store = $data['store'];
}
if (array_key_exists('generation', $data)) {
if (!is_array($data['generation'])) {
throw new InvalidArgumentException('Preview generation configuration must be an object');
if (array_key_exists('maxSourceSize', $data)) {
if (!is_int($data['maxSourceSize']) || $data['maxSourceSize'] < 1) {
throw new InvalidArgumentException('Preview maximum source size must be a positive integer');
}
$this->generation->jsonDeserialize($data['generation']);
$this->maxSourceSize = $data['maxSourceSize'];
}
if (array_key_exists('variants', $data)) {
@@ -71,9 +70,9 @@ final class TenantPreview extends JsonSerializableObject
return $this->store;
}
public function generation(): TenantPreviewGeneration
public function maxSourceSize(): int
{
return $this->generation;
return $this->maxSourceSize;
}
public function variants(): TenantPreviewVariants
@@ -1,72 +0,0 @@
<?php
declare(strict_types=1);
namespace KTXC\Models\Tenant;
use InvalidArgumentException;
use KTXF\Json\JsonSerializableObject;
final class TenantPreviewGeneration extends JsonSerializableObject
{
public const MODE_LAZY = 'lazy';
public const MODE_EAGER_WITH_LAZY_FALLBACK = 'eager-with-lazy-fallback';
protected string $mode = self::MODE_EAGER_WITH_LAZY_FALLBACK;
protected int $maxSourceSize = 104857600;
protected int $timeoutSeconds = 30;
protected int $retryDelaySeconds = 3600;
public function jsonDeserialize(array|string $data): static
{
if (is_string($data)) {
$data = json_decode($data, true, flags: JSON_THROW_ON_ERROR);
}
if (array_key_exists('mode', $data)) {
if (!is_string($data['mode']) || !in_array($data['mode'], [
self::MODE_LAZY,
self::MODE_EAGER_WITH_LAZY_FALLBACK,
], true)) {
throw new InvalidArgumentException('Unsupported preview generation mode');
}
$this->mode = $data['mode'];
}
foreach ([
'maxSourceSize' => 'maximum source size',
'timeoutSeconds' => 'timeout',
'retryDelaySeconds' => 'retry delay',
] as $property => $label) {
if (!array_key_exists($property, $data)) {
continue;
}
if (!is_int($data[$property]) || $data[$property] < 1) {
throw new InvalidArgumentException("Preview {$label} must be a positive integer");
}
$this->$property = $data[$property];
}
return $this;
}
public function mode(): string
{
return $this->mode;
}
public function maxSourceSize(): int
{
return $this->maxSourceSize;
}
public function timeoutSeconds(): int
{
return $this->timeoutSeconds;
}
public function retryDelaySeconds(): int
{
return $this->retryDelaySeconds;
}
}