1 | <?php |
||
35 | class Field implements JsonSerializable |
||
36 | { |
||
37 | protected $name; |
||
38 | |||
39 | protected $id; |
||
40 | |||
41 | protected $label; |
||
42 | |||
43 | protected $errors = []; |
||
44 | |||
45 | protected $type = 'text'; |
||
46 | |||
47 | protected $value; |
||
48 | |||
49 | protected $attribs = []; |
||
50 | |||
51 | protected $options = []; |
||
52 | |||
53 | protected $help; |
||
54 | |||
55 | /** |
||
56 | * Create a new form field |
||
57 | * |
||
58 | * @param string $name name of field |
||
59 | * |
||
60 | * @access public |
||
61 | */ |
||
62 | 16 | public function __construct($name) |
|
66 | |||
67 | /** |
||
68 | * Set label |
||
69 | * |
||
70 | * @param string $label Label for field |
||
71 | * |
||
72 | * @return $this |
||
73 | * |
||
74 | * @access public |
||
75 | */ |
||
76 | 2 | public function label($label) |
|
81 | |||
82 | /** |
||
83 | * Set error mesages |
||
84 | * |
||
85 | * @param array $errors array of error messages |
||
86 | * |
||
87 | * @return $this |
||
88 | * |
||
89 | * @access public |
||
90 | */ |
||
91 | 2 | public function errors(array $errors) |
|
96 | |||
97 | /** |
||
98 | * Set type |
||
99 | * |
||
100 | * @param string $type field type |
||
101 | * |
||
102 | * @return $this |
||
103 | * |
||
104 | * @access public |
||
105 | */ |
||
106 | 2 | public function type($type) |
|
111 | |||
112 | /** |
||
113 | * Fill value |
||
114 | * |
||
115 | * @param mixed $value value of field |
||
116 | * |
||
117 | * @return $this |
||
118 | * |
||
119 | * @access public |
||
120 | */ |
||
121 | 3 | public function fill($value) |
|
126 | |||
127 | /** |
||
128 | * Set attributes |
||
129 | * |
||
130 | * @param array $attribs attributes for field |
||
131 | * |
||
132 | * @return $this |
||
133 | * |
||
134 | * @access public |
||
135 | */ |
||
136 | 3 | public function attribs(array $attribs) |
|
145 | |||
146 | /** |
||
147 | * Set options |
||
148 | * |
||
149 | * @param array $options options for field |
||
150 | * |
||
151 | * @return $this |
||
152 | * |
||
153 | * @access public |
||
154 | */ |
||
155 | 2 | public function options(array $options) |
|
160 | |||
161 | /** |
||
162 | * Set help text for field |
||
163 | * |
||
164 | * @param string $text help text for field |
||
165 | * |
||
166 | * @return $this |
||
167 | * |
||
168 | * @access public |
||
169 | */ |
||
170 | 1 | public function help($text) |
|
175 | |||
176 | /** |
||
177 | * Get field spec as array |
||
178 | * |
||
179 | * @return array |
||
180 | * |
||
181 | * @access public |
||
182 | */ |
||
183 | 1 | public function getSpec() |
|
193 | |||
194 | /** |
||
195 | * Magic getter |
||
196 | * |
||
197 | * @param string $name name of property |
||
198 | * |
||
199 | * @return mixed |
||
200 | * |
||
201 | * @access public |
||
202 | */ |
||
203 | 12 | public function __get($name) |
|
211 | |||
212 | /** |
||
213 | * JsonSerialize |
||
214 | * |
||
215 | * @return mixed |
||
216 | * |
||
217 | * @access public |
||
218 | */ |
||
219 | public function jsonSerialize() |
||
223 | |||
224 | /** |
||
225 | * GetArrayCopy |
||
226 | * |
||
227 | * @return mixed |
||
228 | * |
||
229 | * @access public |
||
230 | */ |
||
231 | public function getArrayCopy() |
||
244 | |||
245 | } |
||
246 |