2020-08-22 22:43:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Client;
|
|
|
|
|
2020-09-23 04:12:00 +00:00
|
|
|
use BadMethodCallException;
|
2020-08-22 22:43:28 +00:00
|
|
|
use Pterodactyl\Models\EggVariable;
|
|
|
|
|
|
|
|
class EggVariableTransformer extends BaseClientTransformer
|
|
|
|
{
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return EggVariable::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(EggVariable $variable)
|
|
|
|
{
|
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.
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$variable->user_viewable) {
|
|
|
|
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 [
|
|
|
|
'name' => $variable->name,
|
|
|
|
'description' => $variable->description,
|
|
|
|
'env_variable' => $variable->env_variable,
|
|
|
|
'default_value' => $variable->default_value,
|
|
|
|
'server_value' => $variable->server_value,
|
|
|
|
'is_editable' => $variable->user_editable,
|
|
|
|
'rules' => $variable->rules,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|