112 lines
3.8 KiB
PHP
112 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Projects;
|
|
|
|
use App\Enums\PhpVersion;
|
|
use App\Enums\ProjectType;
|
|
use App\Enums\SmtpEnum;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
|
|
|
class StoreProjectRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return Auth::check();
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'https' => $this->https ? true : false
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
$rules = [];
|
|
if (Auth::user()->equipe_web_member) {
|
|
$rules = [
|
|
'prod_login' => 'required|json',
|
|
'dev_login' => 'required|json',
|
|
'prod_bo_url' => 'required|url',
|
|
'dev_bo_url' => 'required|url',
|
|
];
|
|
}
|
|
return \array_merge($rules, [
|
|
'name' => 'required|string|min:2|max:255',
|
|
'display_name' => 'required|string|min:2|max:255',
|
|
'php' => ['required', new EnumIsValidRule(PhpVersion::class)],
|
|
'type' => ['required', new EnumIsValidRule(ProjectType::class)],
|
|
|
|
'https' => 'required|boolean',
|
|
|
|
'prod_haproxy_id' => 'nullable|regex:/^P?\d{3}$/',
|
|
'dev_haproxy_id' => 'nullable|regex:/^P?\d{3}$/',
|
|
|
|
'prod_url' => 'nullable|url|max:255',
|
|
'dev_url' => 'nullable|url|max:255',
|
|
|
|
'prod_document_root' => 'nullable|regex:/^(\/)?([^\/\0]+(\/)?)+$/|max:255',
|
|
'dev_document_root' => 'nullable|regex:/^(\/)?([^\/\0]+(\/)?)+$/|max:255',
|
|
|
|
'prod_unix_user' => 'nullable|string|max:255',
|
|
'prod_unix_pwd' => 'nullable|string|max:255',
|
|
'dev_unix_user' => 'nullable|string|max:255',
|
|
'dev_unix_pwd' => 'nullable|string|max:255',
|
|
|
|
'prod_db_user' => 'nullable|string|max:255',
|
|
'prod_db_pwd' => 'nullable|string|max:255',
|
|
'dev_db_user' => 'nullable|string|max:255',
|
|
'dev_db_pwd' => 'nullable|string|max:255',
|
|
|
|
'prod_db_schema' => 'nullable|string|max:255',
|
|
'dev_db_schema' => 'nullable|string|max:255',
|
|
|
|
'prod_db_server_id' => 'sometimes|exists:servers,id',
|
|
'dev_db_server_id' => 'sometimes|exists:servers,id',
|
|
'prod_web_server_id' => 'sometimes|exists:servers,id',
|
|
'dev_web_server_id' => 'sometimes|exists:servers,id',
|
|
|
|
'prod_comment' => 'nullable|string|max:255',
|
|
'dev_comment' => 'nullable|string|max:255',
|
|
|
|
'prod_eai' => 'nullable|string|max:255',
|
|
'dev_eai' => 'nullable|string|max:255',
|
|
|
|
'prod_whitelist_fw' => 'nullable|string|max:255',
|
|
'dev_whitelist_fw' => 'nullable|string|max:255',
|
|
|
|
'dev_htaccess_user' => 'required|string|min:2|max:255',
|
|
'dev_htaccess_pwd' => 'required|string|min:2|max:255',
|
|
|
|
'prod_ga_id' => 'nullable|string|max:50',
|
|
|
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'prod_laravel_app_key' => 'nullable|regex:/^base64:(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/|max:255',
|
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'dev_laravel_app_key' => 'nullable|regex:/^base64:(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/|max:255',
|
|
|
|
'prod_smtp_config' => [
|
|
'required', new EnumIsValidRule(SmtpEnum::class)
|
|
],
|
|
'prod_smtp_key' => 'required_if:prod_smtp_config,3|max:255|max:255',
|
|
]);
|
|
}
|
|
}
|