api(application): v2 backport

This commit is contained in:
Matthew Penner 2022-12-14 17:05:46 -07:00
parent 4cd0bee231
commit 67bf3e342e
No known key found for this signature in database
172 changed files with 2922 additions and 1579 deletions

View file

@ -3,31 +3,32 @@
namespace Pterodactyl\Transformers\Api\Client;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Transformers\Api\Transformer;
class EggVariableTransformer extends BaseClientTransformer
class EggVariableTransformer extends Transformer
{
public function getResourceName(): string
{
return EggVariable::RESOURCE_NAME;
}
public function transform(EggVariable $variable): array
public function transform(EggVariable $model): array
{
// 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.
if (!$variable->user_viewable) {
if (!$model->user_viewable) {
throw new \BadMethodCallException('Cannot transform a hidden egg variable in a client transformer.');
}
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,
'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,
];
}
}