2019-03-23 17:47:20 -07:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2019-03-23 17:47:20 -07:00
|
|
|
namespace Pterodactyl\Transformers\Api\Client;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Extensions\Scribe\Attributes\ResponseField;
|
2019-03-23 17:47:20 -07:00
|
|
|
use Pterodactyl\Models\Allocation;
|
2026-10-05 18:10:18 -04:00
|
|
|
use UnexpectedValueException;
|
2019-03-23 17:47:20 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
#[ResponseField('notes', example: 'Primary game port', nullable: true)]
|
2019-03-23 17:47:20 -07:00
|
|
|
class AllocationTransformer extends BaseClientTransformer
|
|
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
protected array $eagerLoads = ['server'];
|
|
|
|
|
|
2019-03-23 17:47:20 -07:00
|
|
|
/**
|
|
|
|
|
* 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
|
2019-03-23 17:47:20 -07:00
|
|
|
{
|
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.');
|
|
|
|
|
|
2019-03-23 17:47:20 -07:00
|
|
|
return [
|
2020-07-09 20:36:08 -07:00
|
|
|
'id' => $model->id,
|
2019-03-23 17:47:20 -07:00
|
|
|
'ip' => $model->ip,
|
2020-07-09 19:17:24 -07:00
|
|
|
'ip_alias' => $model->ip_alias,
|
2019-03-23 17:47:20 -07:00
|
|
|
'port' => $model->port,
|
2020-07-09 20:36:08 -07:00
|
|
|
'notes' => $model->notes,
|
2026-10-05 18:10:18 -04:00
|
|
|
'is_default' => $server->allocation_id === $model->id,
|
2019-03-23 17:47:20 -07:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|