Files
pterodactyl-panel/app/Transformers/Api/Client/AllocationTransformer.php
T

42 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Transformers\Api\Client;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Extensions\Scribe\Attributes\ResponseField;
use Pterodactyl\Models\Allocation;
2026-10-05 18:10:18 -04:00
use UnexpectedValueException;
2026-10-05 18:10:18 -04:00
#[ResponseField('notes', example: 'Primary game port', nullable: true)]
class AllocationTransformer extends BaseClientTransformer
{
2026-10-05 18:10:18 -04:00
protected array $eagerLoads = ['server'];
/**
* Return the resource name for the JSONAPI output.
*/
public function getResourceName(): string
{
return 'allocation';
}
2026-10-05 18:10:18 -04:00
/**
* @return ApiPayload
*/
2022-10-14 10:59:20 -06:00
public function transform(Allocation $model): array
{
2026-10-05 18:10:18 -04:00
$model->loadMissing('server');
$server = $model->server ?? throw new UnexpectedValueException('The allocation does not belong to a server.');
return [
'id' => $model->id,
'ip' => $model->ip,
'ip_alias' => $model->ip_alias,
'port' => $model->port,
'notes' => $model->notes,
2026-10-05 18:10:18 -04:00
'is_default' => $server->allocation_id === $model->id,
];
}
}