Files
dockerfile.nyxtex.com/app/Http/Requests/DockerImageBuildRequest.php
RDarius 9fbec77ac7
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
build logs
2026-04-24 14:59:20 +03:00

69 lines
2.1 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class DockerImageBuildRequest extends FormRequest
{
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$environment = collect($this->input('environment', []))
->map(fn (mixed $variable): mixed => is_array($variable)
? [
'key' => isset($variable['key']) ? trim((string) $variable['key']) : null,
'value' => isset($variable['value']) ? (string) $variable['value'] : null,
]
: $variable
)
->all();
$this->merge([
'dockerfile' => trim((string) $this->input('dockerfile', '')),
'environment' => $environment,
'image_name' => trim((string) $this->input('image_name', '')),
'image_tag' => trim((string) $this->input('image_tag', '')),
]);
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'dockerfile' => ['required', 'string', 'max:20000'],
'image_name' => ['required', 'string', 'max:255', 'regex:/^\S+$/'],
'image_tag' => ['required', 'string', 'max:128', 'regex:/^\S+$/'],
'environment' => ['sometimes', 'array', 'max:25'],
'environment.*.key' => [
'nullable',
'required_with:environment.*.value',
'string',
'max:100',
'regex:/^[A-Za-z_][A-Za-z0-9_]*$/',
],
'environment.*.value' => [
'nullable',
'required_with:environment.*.key',
'string',
'max:5000',
],
];
}
}