forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerVariableTransformer.php
More file actions
48 lines (40 loc) · 1.25 KB
/
ServerVariableTransformer.php
File metadata and controls
48 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Pterodactyl\Transformers\Api\Application;
use League\Fractal\Resource\Item;
use Pterodactyl\Models\EggVariable;
use League\Fractal\Resource\NullResource;
use Pterodactyl\Services\Acl\Api\AdminAcl;
class ServerVariableTransformer extends BaseTransformer
{
/**
* List of resources that can be included.
*/
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.
*/
public function transform(EggVariable $variable): array
{
return $variable->toArray();
}
/**
* Return the parent service variable data.
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeParent(EggVariable $variable): Item|NullResource
{
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
return $this->null();
}
$variable->loadMissing('variable');
return $this->item($variable->getRelation('variable'), $this->makeTransformer(EggVariableTransformer::class), 'variable');
}
}