Files

67 lines
2.1 KiB
PHP
Raw Permalink Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
2026-10-12 02:24:41 -04:00
use Closure;
use Illuminate\Validation\Validator;
use Pterodactyl\Http\Requests\Concerns\FiltersDeployTags;
class GetDeployableNodesRequest extends GetNodesRequest
{
2026-10-12 02:24:41 -04:00
use FiltersDeployTags;
2026-10-05 18:10:18 -04:00
/**
* @return ValidationRules
*/
public function rules(): array
{
return [
2026-10-05 18:10:18 -04:00
'page' => ['sometimes', 'integer', 'min:1'],
'per_page' => ['sometimes', 'integer', 'min:1', 'max:100'],
'memory' => ['required', 'integer', 'min:0'],
'disk' => ['required', 'integer', 'min:0'],
'location_ids' => ['sometimes', 'array'],
'location_ids.*' => ['integer'],
2026-10-12 02:24:41 -04:00
'tags' => ['sometimes', 'array', 'list'],
'tags.*' => ['string'],
'egg' => ['sometimes', 'integer', 'exists:eggs,id'],
2026-10-05 18:10:18 -04:00
];
}
2026-10-12 02:24:41 -04:00
/**
* @return list<Closure(Validator): void>
*/
public function after(): array
{
return [$this->validateDeployTagsExist(...)];
}
2026-10-05 18:10:18 -04:00
/**
2026-10-11 09:54:41 -04:00
* The deployment criteria, read with Laravel's typed accessors. Without a page, every
* viable node is listed.
*
2026-10-12 02:24:41 -04:00
* @return array{memory: int, disk: int, location_ids: list<int>, tags: string[], egg: int|null, per_page: int|null, page: int|null}
2026-10-05 18:10:18 -04:00
*/
public function payload(): array
{
2026-10-11 09:54:41 -04:00
$validated = $this->safe();
2026-10-05 18:10:18 -04:00
return [
2026-10-11 09:54:41 -04:00
'memory' => $validated->integer('memory'),
'disk' => $validated->integer('disk'),
'location_ids' => array_map(fn (int|string $key): int => $validated->integer('location_ids.'.$key), array_keys($validated->array('location_ids'))),
2026-10-12 02:24:41 -04:00
'tags' => $this->resolveDeployTagSlugs(),
'egg' => $validated->filled('egg') ? $validated->integer('egg') : null,
2026-10-11 09:54:41 -04:00
'per_page' => $validated->filled('per_page') ? $validated->integer('per_page') : null,
'page' => $validated->filled('page') ? $validated->integer('page') : null,
];
}
2026-10-12 02:24:41 -04:00
protected function deployTagsField(): string
{
return 'tags';
}
}