2020-08-22 18:13:59 -07:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2020-08-22 18:13:59 -07:00
|
|
|
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Startup;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Pterodactyl\Contracts\Http\ClientPermissionsRequest;
|
|
|
|
|
use Pterodactyl\Enum\Permissions;
|
2020-08-22 18:13:59 -07:00
|
|
|
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Models\EggVariable;
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2020-08-22 18:13:59 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
class UpdateStartupVariableRequest extends ClientApiRequest implements ClientPermissionsRequest
|
2020-08-22 18:13:59 -07:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
private ?EggVariable $variable = null;
|
|
|
|
|
|
|
|
|
|
private bool $resolvedVariable = false;
|
|
|
|
|
|
2022-10-14 10:59:20 -06:00
|
|
|
public function permission(): string
|
2020-08-22 18:13:59 -07:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Permissions::StartupUpdate->value;
|
2020-08-22 18:13:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* The value is validated with the egg variable's own rules when the variable can be edited.
|
|
|
|
|
*
|
|
|
|
|
* @return ValidationRules
|
2020-08-22 18:13:59 -07:00
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$variable = $this->filled('key') ? $this->variable() : null;
|
|
|
|
|
|
2020-08-22 18:13:59 -07:00
|
|
|
return [
|
2026-10-05 18:10:18 -04:00
|
|
|
'key' => ['required', 'string'],
|
|
|
|
|
'value' => $variable instanceof EggVariable && $variable->user_viewable && $variable->user_editable
|
|
|
|
|
? ['present', ...$this->variableRules($variable)]
|
|
|
|
|
: 'present',
|
2020-08-22 18:13:59 -07:00
|
|
|
];
|
|
|
|
|
}
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The server's egg variable named by the request, with its server value loaded.
|
|
|
|
|
*/
|
|
|
|
|
public function variable(): ?EggVariable
|
|
|
|
|
{
|
|
|
|
|
if (! $this->resolvedVariable) {
|
|
|
|
|
$this->variable = $this->parameter('server', Server::class)
|
|
|
|
|
->variables()
|
|
|
|
|
->where('env_variable', $this->string('key')->toString())
|
|
|
|
|
->first();
|
|
|
|
|
$this->resolvedVariable = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->variable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Split the variable's pipe-delimited rule string the way the validator would, keeping
|
|
|
|
|
* a regex rule intact.
|
|
|
|
|
*
|
|
|
|
|
* @return list<string>
|
|
|
|
|
*/
|
|
|
|
|
private function variableRules(EggVariable $variable): array
|
|
|
|
|
{
|
2026-10-11 22:55:07 -04:00
|
|
|
$rules = $variable->rules ?? '';
|
|
|
|
|
|
|
|
|
|
return Str::startsWith($rules, 'regex:') ? [$rules] : explode('|', $rules);
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
2020-08-22 18:13:59 -07:00
|
|
|
}
|