misc_pterodactyl-panel/app/Transformers/Api/Application/ServerVariableTransformer.php
2021-10-30 13:41:38 -07:00

47 lines
1.2 KiB
PHP

<?php
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Models\ServerVariable;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Transformers\Api\Transformer;
class ServerVariableTransformer extends Transformer
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = ['parent'];
/**
* Return the resource name for the JSONAPI output.
*/
public function getResourceName(): string
{
return ServerVariable::RESOURCE_NAME;
}
public function transform(EggVariable $model): array
{
return $model->toArray();
}
/**
* Return the parent service variable data.
*
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*/
public function includeParent(EggVariable $variable)
{
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
return $this->null();
}
// TODO: confirm this code?
// @phpstan-ignore-next-line This might actually be wrong, not sure?
return $this->item($variable->variable, new EggVariableTransformer());
}
}