1 | <?php |
||
8 | abstract class Field |
||
9 | { |
||
10 | /** |
||
11 | * The form of field. |
||
12 | * |
||
13 | * @var Form |
||
14 | */ |
||
15 | protected $form; |
||
16 | |||
17 | /** |
||
18 | * The name of field. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $name; |
||
23 | |||
24 | /** |
||
25 | * The template of field. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $template = 'fields.input'; |
||
30 | |||
31 | /** |
||
32 | * The rules of field. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $rules; |
||
37 | |||
38 | /** |
||
39 | * The map of rules. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $ruleMap = []; |
||
44 | |||
45 | /** |
||
46 | * The default map of rules. |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $defaultRulesMap = [ |
||
51 | 'required' => 'required' |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * Get the name of field. |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getName(): string |
||
63 | |||
64 | /** |
||
65 | * Get the template of field. |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | public function getTemplate(): string |
||
73 | |||
74 | /** |
||
75 | * Get the label of field. |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | public function getLabel(): string |
||
92 | |||
93 | /** |
||
94 | * Get the placeholder of field. |
||
95 | * |
||
96 | * @return null|string |
||
97 | */ |
||
98 | public function getPlaceholder() |
||
106 | |||
107 | /** |
||
108 | * Get the text of field. |
||
109 | * |
||
110 | * @return null|string |
||
111 | */ |
||
112 | public function getText() |
||
120 | |||
121 | /** |
||
122 | * Set the name of field. |
||
123 | * |
||
124 | * @param string $name |
||
125 | */ |
||
126 | public function setName(string $name) |
||
130 | |||
131 | /** |
||
132 | * Set the rules of field. |
||
133 | * |
||
134 | * @param array $rules |
||
135 | */ |
||
136 | public function setRules(array $rules) |
||
140 | |||
141 | /** |
||
142 | * Set the form of field. |
||
143 | * |
||
144 | * @param Form $form |
||
145 | */ |
||
146 | public function setForm(Form $form) |
||
150 | |||
151 | /** |
||
152 | * Get html of attributes. |
||
153 | * |
||
154 | * @return HtmlString |
||
155 | */ |
||
156 | public function attributes() |
||
172 | |||
173 | /** |
||
174 | * Get default and field rule maps. |
||
175 | * |
||
176 | * @return array |
||
177 | */ |
||
178 | protected function getRuleMaps() |
||
184 | |||
185 | /** |
||
186 | * Get html of boolean attribute. |
||
187 | * |
||
188 | * @param string $map |
||
189 | * @param string $rule |
||
190 | * @return string |
||
191 | */ |
||
192 | protected function getHtmlOfBooleanAttribute($map, $rule): string |
||
200 | |||
201 | /** |
||
202 | * Get html of attribute. |
||
203 | * |
||
204 | * @param array $map |
||
205 | * @param string $rule |
||
206 | * @return string |
||
207 | */ |
||
208 | protected function getHtmlOfAttribute($map, $rule): string |
||
222 | } |
||
223 |