eaea5f4c83
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?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;
|
|
}
|
|
}
|