2018-01-20 03:47:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Application;
|
|
|
|
|
2020-12-04 17:56:44 +00:00
|
|
|
use Pterodactyl\Models\EggVariable;
|
2018-01-20 03:47:06 +00:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
|
|
|
|
|
|
|
class ServerVariableTransformer extends BaseTransformer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* List of resources that can be included.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2022-05-04 23:11:42 +00:00
|
|
|
protected array $availableIncludes = ['parent'];
|
2018-01-20 03:47:06 +00:00
|
|
|
|
2018-01-26 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* Return the resource name for the JSONAPI output.
|
|
|
|
*/
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return ServerVariable::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
/**
|
|
|
|
* Return a generic transformed server variable array.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-12-04 17:56:44 +00:00
|
|
|
public function transform(EggVariable $variable)
|
2018-01-20 03:47:06 +00:00
|
|
|
{
|
|
|
|
return $variable->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the parent service variable data.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
2021-01-23 20:33:34 +00:00
|
|
|
*
|
2018-05-13 16:19:35 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
2018-01-20 03:47:06 +00:00
|
|
|
*/
|
2020-12-04 17:56:44 +00:00
|
|
|
public function includeParent(EggVariable $variable)
|
2018-01-20 03:47:06 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
2018-01-20 03:47:06 +00:00
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
|
|
|
$variable->loadMissing('variable');
|
|
|
|
|
|
|
|
return $this->item($variable->getRelation('variable'), $this->makeTransformer(EggVariableTransformer::class), 'variable');
|
|
|
|
}
|
|
|
|
}
|