2020-08-22 22:43:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Client;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\EggVariable;
|
2022-12-15 00:05:46 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Transformer;
|
2020-08-22 22:43:28 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
class EggVariableTransformer extends Transformer
|
2020-08-22 22:43:28 +00:00
|
|
|
{
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return EggVariable::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
public function transform(EggVariable $model): array
|
2020-08-22 22:43:28 +00:00
|
|
|
{
|
2020-09-23 04:12:00 +00:00
|
|
|
// This guards against someone incorrectly retrieving variables (haha, me) and then passing
|
|
|
|
// them into the transformer and along to the user. Just throw an exception and break the entire
|
|
|
|
// pathway since you should never be exposing these types of variables to a client.
|
2022-12-15 00:05:46 +00:00
|
|
|
if (!$model->user_viewable) {
|
2022-11-29 17:53:59 +00:00
|
|
|
throw new \BadMethodCallException('Cannot transform a hidden egg variable in a client transformer.');
|
2020-09-23 04:12:00 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 22:43:28 +00:00
|
|
|
return [
|
2022-12-15 00:05:46 +00:00
|
|
|
'name' => $model->name,
|
|
|
|
'description' => $model->description,
|
|
|
|
'env_variable' => $model->env_variable,
|
|
|
|
'default_value' => $model->default_value,
|
|
|
|
'server_value' => $model->server_value,
|
|
|
|
'is_editable' => $model->user_editable,
|
|
|
|
'rules' => $model->rules,
|
2020-08-22 22:43:28 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|