Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Transformers/Api/Client/EggVariableTransformer.php
10284 views
1
<?php
2
3
namespace Pterodactyl\Transformers\Api\Client;
4
5
use Pterodactyl\Models\EggVariable;
6
7
class EggVariableTransformer extends BaseClientTransformer
8
{
9
public function getResourceName(): string
10
{
11
return EggVariable::RESOURCE_NAME;
12
}
13
14
public function transform(EggVariable $variable): array
15
{
16
// This guards against someone incorrectly retrieving variables (haha, me) and then passing
17
// them into the transformer and along to the user. Just throw an exception and break the entire
18
// pathway since you should never be exposing these types of variables to a client.
19
if (!$variable->user_viewable) {
20
throw new \BadMethodCallException('Cannot transform a hidden egg variable in a client transformer.');
21
}
22
23
return [
24
'name' => $variable->name,
25
'description' => $variable->description,
26
'env_variable' => $variable->env_variable,
27
'default_value' => $variable->default_value,
28
'server_value' => $variable->server_value,
29
'is_editable' => $variable->user_editable,
30
'rules' => $variable->rules,
31
];
32
}
33
}
34
35