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
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = ['parent'];
|
|
|
|
|
2018-01-26 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* Return the resource name for the JSONAPI output.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return ServerVariable::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
/**
|
|
|
|
* Return a generic transformed server variable array.
|
|
|
|
*
|
2020-12-04 17:56:44 +00:00
|
|
|
* @param \Pterodactyl\Models\EggVariable $variable
|
2018-01-20 03:47:06 +00:00
|
|
|
* @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.
|
|
|
|
*
|
2020-12-04 17:56:44 +00:00
|
|
|
* @param \Pterodactyl\Models\EggVariable $variable
|
2018-01-20 03:47:06 +00:00
|
|
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
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
|
|
|
{
|
|
|
|
if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
|
|
|
$variable->loadMissing('variable');
|
|
|
|
|
|
|
|
return $this->item($variable->getRelation('variable'), $this->makeTransformer(EggVariableTransformer::class), 'variable');
|
|
|
|
}
|
|
|
|
}
|