lasthourcloud/app/Livewire/Project/Shared/EnvironmentVariable/Add.php

79 lines
2.0 KiB
PHP
Raw Normal View History

2023-05-04 20:29:14 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Shared\EnvironmentVariable;
2023-05-04 20:29:14 +00:00
use Livewire\Component;
class Add extends Component
{
public $parameters;
2024-06-10 20:43:34 +00:00
2024-04-15 10:46:22 +00:00
public bool $shared = false;
2024-06-10 20:43:34 +00:00
2023-06-05 10:07:55 +00:00
public bool $is_preview = false;
2024-06-10 20:43:34 +00:00
2023-05-04 20:29:14 +00:00
public string $key;
2024-06-10 20:43:34 +00:00
2023-09-26 12:45:52 +00:00
public ?string $value = null;
2024-06-10 20:43:34 +00:00
2023-05-04 20:29:14 +00:00
public bool $is_build_time = false;
2024-06-10 20:43:34 +00:00
2024-03-15 21:02:37 +00:00
public bool $is_multiline = false;
2024-06-10 20:43:34 +00:00
2024-04-15 10:46:22 +00:00
public bool $is_literal = false;
2023-05-04 20:29:14 +00:00
2023-05-05 12:20:10 +00:00
protected $listeners = ['clearAddEnv' => 'clear'];
2024-06-10 20:43:34 +00:00
2023-05-05 07:28:00 +00:00
protected $rules = [
'key' => 'required|string',
2023-09-26 12:45:52 +00:00
'value' => 'nullable',
2023-05-05 07:28:00 +00:00
'is_build_time' => 'required|boolean',
2024-03-15 21:02:37 +00:00
'is_multiline' => 'required|boolean',
2024-04-15 10:46:22 +00:00
'is_literal' => 'required|boolean',
2023-05-05 07:28:00 +00:00
];
2024-06-10 20:43:34 +00:00
2023-06-16 10:35:40 +00:00
protected $validationAttributes = [
'key' => 'key',
'value' => 'value',
'is_build_time' => 'build',
2024-03-15 21:02:37 +00:00
'is_multiline' => 'multiline',
2024-04-15 10:46:22 +00:00
'is_literal' => 'literal',
2023-06-16 10:35:40 +00:00
];
2023-05-04 20:29:14 +00:00
public function mount()
{
$this->parameters = get_route_parameters();
2023-05-04 20:29:14 +00:00
}
2023-05-04 20:29:14 +00:00
public function submit()
{
2023-05-05 07:28:00 +00:00
$this->validate();
2024-01-31 12:40:15 +00:00
if (str($this->value)->startsWith('{{') && str($this->value)->endsWith('}}')) {
2024-06-10 20:43:34 +00:00
$type = str($this->value)->after('{{')->before('.')->value;
if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
2024-01-31 12:40:15 +00:00
return;
}
}
2023-12-07 18:06:32 +00:00
$this->dispatch('saveKey', [
2023-05-05 12:20:10 +00:00
'key' => $this->key,
'value' => $this->value,
'is_build_time' => $this->is_build_time,
2024-03-15 21:02:37 +00:00
'is_multiline' => $this->is_multiline,
2024-04-15 10:46:22 +00:00
'is_literal' => $this->is_literal,
2023-06-05 10:07:55 +00:00
'is_preview' => $this->is_preview,
2023-05-05 12:20:10 +00:00
]);
2023-07-13 11:16:24 +00:00
$this->clear();
2023-05-05 12:20:10 +00:00
}
2023-05-05 12:20:10 +00:00
public function clear()
{
$this->key = '';
$this->value = '';
$this->is_build_time = false;
2024-03-15 21:02:37 +00:00
$this->is_multiline = false;
2024-04-15 10:46:22 +00:00
$this->is_literal = false;
2023-05-04 20:29:14 +00:00
}
}