2018-01-19 21:47:06 -06:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2018-01-19 21:47:06 -06:00
|
|
|
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;
|
2020-12-04 19:56:44 +02:00
|
|
|
use Pterodactyl\Models\EggVariable;
|
2025-12-20 15:55:13 -08:00
|
|
|
use Pterodactyl\Models\ServerVariable;
|
2018-01-19 21:47:06 -06:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Support\JsonValueGuard;
|
2018-01-19 21:47:06 -06:00
|
|
|
|
|
|
|
|
class ServerVariableTransformer extends BaseTransformer
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* List of resources that can be included.
|
2026-10-05 18:10:18 -04:00
|
|
|
*
|
|
|
|
|
* @var list<string>
|
2018-01-19 21:47:06 -06:00
|
|
|
*/
|
2022-05-04 19:11:42 -04:00
|
|
|
protected array $availableIncludes = ['parent'];
|
2018-01-19 21:47:06 -06:00
|
|
|
|
2018-01-25 21:26:06 -06:00
|
|
|
/**
|
|
|
|
|
* Return the resource name for the JSONAPI output.
|
|
|
|
|
*/
|
|
|
|
|
public function getResourceName(): string
|
|
|
|
|
{
|
|
|
|
|
return ServerVariable::RESOURCE_NAME;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-19 21:47:06 -06:00
|
|
|
/**
|
|
|
|
|
* Return a generic transformed server variable array.
|
2026-10-05 18:10:18 -04:00
|
|
|
*
|
|
|
|
|
* @return ApiPayload
|
2018-01-19 21:47:06 -06:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function transform(EggVariable $variable): array
|
2018-01-19 21:47:06 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$attributes = $variable->attributesToArray();
|
|
|
|
|
JsonValueGuard::assertPayload($attributes);
|
|
|
|
|
|
|
|
|
|
return $attributes;
|
2018-01-19 21:47:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the parent service variable data.
|
|
|
|
|
*
|
2026-10-05 18:10:18 -04:00
|
|
|
* @throws InvalidTransformerLevelException
|
2018-01-19 21:47:06 -06:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function includeParent(EggVariable $variable): Item|NullResource
|
2018-01-19 21:47:06 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
2018-01-19 21:47:06 -06:00
|
|
|
return $this->null();
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->item($variable, $this->makeTransformer(EggVariableTransformer::class), 'variable');
|
2018-01-19 21:47:06 -06:00
|
|
|
}
|
|
|
|
|
}
|