Files

70 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Http\Requests\Api\Admin\Extensions;
use Illuminate\Http\UploadedFile;
use Pterodactyl\Enum\Permissions;
use Pterodactyl\Http\Requests\Api\Admin\AdminApiRequest;
use UnexpectedValueException;
class InstallExtensionRequest extends AdminApiRequest
{
public function permissions(): array
{
return [Permissions::AdminExtensionsInstall];
}
/**
* @return ValidationRules
*/
public function rules(): array
{
return [
'package' => ['required', 'file', 'max:51200'],
'enable' => ['sometimes', 'boolean'],
2026-10-06 14:01:38 -04:00
'replace' => ['sometimes', 'boolean'],
2026-10-05 18:10:18 -04:00
];
}
public function attributes(): array
{
return [
'package' => 'extension package',
];
}
/**
2026-10-06 14:01:38 -04:00
* @return array{package: UploadedFile, enable: bool, replace: bool}
2026-10-05 18:10:18 -04:00
*/
public function payload(): array
{
$package = $this->file('package');
throw_unless($package instanceof UploadedFile, UnexpectedValueException::class, 'Expected an uploaded extension package.');
return [
'package' => $package,
'enable' => $this->boolean('enable', false),
2026-10-06 14:01:38 -04:00
'replace' => $this->boolean('replace', false),
2026-10-05 18:10:18 -04:00
];
}
/**
* {@inheritdoc}
*/
protected function prepareForValidation(): void
{
2026-10-06 14:01:38 -04:00
foreach (['enable', 'replace'] as $key) {
if (! $this->has($key)) {
continue;
}
2026-10-06 14:01:38 -04:00
$value = filter_var($this->input($key), FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE);
if ($value !== null) {
$this->merge([$key => $value]);
}
}
}
2026-10-05 18:10:18 -04:00
}