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> */ 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', ], ]; } }