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 | /** |
||
54 | * Create a new form field |
||
55 | * |
||
56 | * @param string $name name of field |
||
57 | * |
||
58 | * @access public |
||
59 | */ |
||
60 | 15 | public function __construct($name) |
|
64 | |||
65 | /** |
||
66 | * Set label |
||
67 | * |
||
68 | * @param string $label Label for field |
||
69 | * |
||
70 | * @return $this |
||
71 | * |
||
72 | * @access public |
||
73 | */ |
||
74 | 2 | public function label($label) |
|
79 | |||
80 | /** |
||
81 | * Set error mesages |
||
82 | * |
||
83 | * @param array $errors array of error messages |
||
84 | * |
||
85 | * @return $this |
||
86 | * |
||
87 | * @access public |
||
88 | */ |
||
89 | 2 | public function errors(array $errors) |
|
94 | |||
95 | /** |
||
96 | * Set type |
||
97 | * |
||
98 | * @param string $type field type |
||
99 | * |
||
100 | * @return $this |
||
101 | * |
||
102 | * @access public |
||
103 | */ |
||
104 | 2 | public function type($type) |
|
109 | |||
110 | /** |
||
111 | * Fill value |
||
112 | * |
||
113 | * @param mixed $value value of field |
||
114 | * |
||
115 | * @return $this |
||
116 | * |
||
117 | * @access public |
||
118 | */ |
||
119 | 3 | public function fill($value) |
|
124 | |||
125 | /** |
||
126 | * Set attributes |
||
127 | * |
||
128 | * @param array $attribs attributes for field |
||
129 | * |
||
130 | * @return $this |
||
131 | * |
||
132 | * @access public |
||
133 | */ |
||
134 | 3 | public function attribs(array $attribs) |
|
143 | |||
144 | /** |
||
145 | * Set options |
||
146 | * |
||
147 | * @param array $options options for field |
||
148 | * |
||
149 | * @return $this |
||
150 | * |
||
151 | * @access public |
||
152 | */ |
||
153 | 2 | public function options(array $options) |
|
158 | |||
159 | /** |
||
160 | * Get field spec as array |
||
161 | * |
||
162 | * @return array |
||
163 | * |
||
164 | * @access public |
||
165 | */ |
||
166 | 1 | public function getSpec() |
|
176 | |||
177 | /** |
||
178 | * Magic getter |
||
179 | * |
||
180 | * @param string $name name of property |
||
181 | * |
||
182 | * @return mixed |
||
183 | * |
||
184 | * @access public |
||
185 | */ |
||
186 | 11 | public function __get($name) |
|
194 | |||
195 | /** |
||
196 | * JsonSerialize |
||
197 | * |
||
198 | * @return mixed |
||
199 | * |
||
200 | * @access public |
||
201 | */ |
||
202 | public function jsonSerialize() |
||
206 | |||
207 | /** |
||
208 | * GetArrayCopy |
||
209 | * |
||
210 | * @return mixed |
||
211 | * |
||
212 | * @access public |
||
213 | */ |
||
214 | public function getArrayCopy() |
||
227 | |||
228 | } |
||
229 |