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 | * Get the name of field. |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getName(): string |
||
51 | { |
||
52 | return $this->name; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get the template of field. |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getTemplate(): string |
||
61 | { |
||
62 | return $this->template; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get the label of field. |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function getLabel(): string |
||
71 | { |
||
72 | return $this->form->getHelper()->getLabel($this->name); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Get the placeholder of field. |
||
77 | * |
||
78 | * @return null|string |
||
79 | */ |
||
80 | public function getPlaceholder() |
||
81 | { |
||
82 | return $this->form->getHelper()->getPlaceholder($this->name); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Get the text of field. |
||
87 | * |
||
88 | * @return null|string |
||
89 | */ |
||
90 | public function getText() |
||
91 | { |
||
92 | return $this->form->getHelper()->getText($this->name); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Set the name of field. |
||
97 | * |
||
98 | * @param string $name |
||
99 | */ |
||
100 | public function setName(string $name) |
||
104 | |||
105 | /** |
||
106 | * Set the rules of field. |
||
107 | * |
||
108 | * @param array $rules |
||
109 | */ |
||
110 | public function setRules(array $rules) |
||
114 | |||
115 | /** |
||
116 | * Set the form of field. |
||
117 | * |
||
118 | * @param Form $form |
||
119 | */ |
||
120 | public function setForm(Form $form) |
||
124 | |||
125 | public function attributes() |
||
160 | } |
||
161 |