misc_pterodactyl-panel/app/Http/Requests/Server/UpdateStartupParametersFormRequest.php
Dane Everitt 508ff8cfb3
Finish front-end server modification changes.
Everything is back to the point that it was before this massive code overhaul began. FInal steps before merging this into develop will be some unit tests.
2017-10-25 22:33:28 -05:00

61 lines
1.6 KiB
PHP

<?php
namespace Pterodactyl\Http\Requests\Server;
use Pterodactyl\Http\Requests\FrontendUserFormRequest;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
class UpdateStartupParametersFormRequest extends FrontendUserFormRequest
{
/**
* @var array
*/
private $validationAttributes = [];
/**
* Determine if the user has permission to update the startup parameters
* for this server.
*
* @return bool
*/
public function authorize()
{
if (! parent::authorize()) {
return false;
}
return $this->user()->can('edit-startup', $this->attributes->get('server'));
}
/**
* Validate that all of the required fields were passed and that the environment
* variable values meet the defined criteria for those fields.
*
* @return array
*/
public function rules()
{
$repository = $this->container->make(EggVariableRepositoryInterface::class);
$variables = $repository->getEditableVariables($this->attributes->get('server')->egg_id);
$rules = $variables->mapWithKeys(function ($variable) {
$this->validationAttributes['environment.' . $variable->env_variable] = $variable->name;
return ['environment.' . $variable->env_variable => $variable->rules];
})->toArray();
return array_merge($rules, [
'environment' => 'required|array',
]);
}
/**
* Return attributes to provide better naming conventions for error messages.
*
* @return array
*/
public function attributes()
{
return $this->validationAttributes;
}
}