Files
pterodactyl-panel/app/Transformers/Api/Application/ServerVariableTransformer.php
T

59 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Transformers\Api\Application;
2022-10-14 10:59:20 -06:00
use League\Fractal\Resource\Item;
2026-10-05 18:10:18 -04:00
use League\Fractal\Resource\NullResource;
use Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Models\ServerVariable;
use Pterodactyl\Services\Acl\Api\AdminAcl;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Support\JsonValueGuard;
class ServerVariableTransformer extends BaseTransformer
{
/**
* List of resources that can be included.
2026-10-05 18:10:18 -04:00
*
* @var list<string>
*/
protected array $availableIncludes = ['parent'];
/**
* Return the resource name for the JSONAPI output.
*/
public function getResourceName(): string
{
return ServerVariable::RESOURCE_NAME;
}
/**
* Return a generic transformed server variable array.
2026-10-05 18:10:18 -04:00
*
* @return ApiPayload
*/
2022-10-14 10:59:20 -06:00
public function transform(EggVariable $variable): array
{
2026-10-05 18:10:18 -04:00
$attributes = $variable->attributesToArray();
JsonValueGuard::assertPayload($attributes);
return $attributes;
}
/**
* Return the parent service variable data.
*
2026-10-05 18:10:18 -04:00
* @throws InvalidTransformerLevelException
*/
2022-10-14 10:59:20 -06:00
public function includeParent(EggVariable $variable): Item|NullResource
{
2026-10-05 18:10:18 -04:00
if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) {
return $this->null();
}
2026-10-05 18:10:18 -04:00
return $this->item($variable, $this->makeTransformer(EggVariableTransformer::class), 'variable');
}
}