-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.php
More file actions
119 lines (87 loc) · 2.61 KB
/
Copy pathInput.php
File metadata and controls
119 lines (87 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace MazerDev\Dialogify;
use MazerDev\Dialogify\Enums\InputType;
class Input
{
protected InputType $type = InputType::Text;
protected ?string $placeholder = null;
protected mixed $defaultValue = null;
protected bool $required = false;
protected ?int $maxLength = null;
/** @var array<string, string>|null */
protected ?array $options = null;
protected ?string $minDate = null;
protected ?string $maxDate = null;
protected ?int $minuteInterval = null;
public function __construct(
protected string $id,
protected string $label,
) {}
public static function make(string $id, string $label): self
{
return new self($id, $label);
}
public function type(InputType $type): self
{
$this->type = $type;
return $this;
}
public function placeholder(string $text): self
{
$this->placeholder = $text;
return $this;
}
public function defaultValue(mixed $value): self
{
$this->defaultValue = $value;
return $this;
}
public function required(bool $required = true): self
{
$this->required = $required;
return $this;
}
public function maxLength(int $max): self
{
$this->maxLength = $max;
return $this;
}
/** @param array<string, string> $options */
public function options(array $options): self
{
$this->options = $options;
return $this;
}
public function minDate(string $date): self
{
$this->minDate = $date;
return $this;
}
public function maxDate(string $date): self
{
$this->maxDate = $date;
return $this;
}
public function minuteInterval(int $minutes): self
{
$this->minuteInterval = $minutes;
return $this;
}
/** @return array{id: string, label: string, type: string, placeholder: ?string, defaultValue: mixed, required: bool, maxLength: ?int, options: array<string, string>|null, minDate: ?string, maxDate: ?string, minuteInterval: ?int} */
public function toArray(): array
{
return [
'id' => $this->id,
'label' => $this->label,
'type' => $this->type->value,
'placeholder' => $this->placeholder,
'defaultValue' => $this->defaultValue,
'required' => $this->required,
'maxLength' => $this->maxLength,
'options' => $this->options,
'minDate' => $this->minDate,
'maxDate' => $this->maxDate,
'minuteInterval' => $this->minuteInterval,
];
}
}