Files

44 lines
932 B
PHP
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Data;
use InvalidArgumentException;
final readonly class AllocationRange
{
public function __construct(
public int $start,
public int $end,
) {}
public static function fromConfig(mixed $start, mixed $end): ?self
{
if (! $start || ! $end) {
return null;
}
return new self(
self::integerLike($start, 'start'),
self::integerLike($end, 'end'),
);
}
private static function integerLike(mixed $value, string $name): int
{
if (is_int($value)) {
return $value;
}
if (is_string($value) && preg_match('/^-?\d+$/', $value)) {
return (int) $value;
}
throw new InvalidArgumentException(sprintf(
'Expected allocation range %s to be an integer-like value.',
$name,
));
}
}