1 | <?php |
||
24 | class Fieldset extends AbstractInput |
||
25 | { |
||
26 | /** |
||
27 | * |
||
28 | * A builder to create input objects. |
||
29 | * |
||
30 | * @var BuilderInterface |
||
31 | * |
||
32 | */ |
||
33 | protected $builder; |
||
34 | |||
35 | /** |
||
36 | * |
||
37 | * A filter for the fieldset values. |
||
38 | * |
||
39 | * @var FilterInterface |
||
40 | * |
||
41 | */ |
||
42 | protected $filter; |
||
43 | |||
44 | /** |
||
45 | * |
||
46 | * Inputs in the fieldset. |
||
47 | * |
||
48 | * @var array |
||
49 | * |
||
50 | */ |
||
51 | protected $inputs = []; |
||
52 | |||
53 | /** |
||
54 | * |
||
55 | * Object for retaining information about options available to the form |
||
56 | * inputs. |
||
57 | * |
||
58 | * @var mixed |
||
59 | * |
||
60 | */ |
||
61 | protected $options; |
||
62 | |||
63 | /** |
||
64 | * |
||
65 | * Property for storing the result of the last filter() call. |
||
66 | * |
||
67 | * @var bool |
||
68 | * |
||
69 | */ |
||
70 | protected $success; |
||
71 | |||
72 | /** |
||
73 | * |
||
74 | * Failures in the fieldset. |
||
75 | * |
||
76 | * @var ArrayObject|null |
||
77 | * |
||
78 | */ |
||
79 | protected $failures; |
||
80 | |||
81 | /** |
||
82 | * |
||
83 | * Constructor. |
||
84 | * |
||
85 | * @param BuilderInterface $builder An object to build input objects. |
||
86 | * |
||
87 | * @param FilterInterface $filter A filter object for this fieldset. |
||
88 | * |
||
89 | * @param object $options An arbitrary options object for use when setting |
||
90 | * up inputs and filters. |
||
91 | * |
||
92 | */ |
||
93 | public function __construct( |
||
103 | |||
104 | /** |
||
105 | * |
||
106 | * Gets an input value from this fieldset. |
||
107 | * |
||
108 | * @param string $name The input name. |
||
109 | * |
||
110 | * @return mixed The input value. |
||
111 | * |
||
112 | */ |
||
113 | public function __get($name) |
||
117 | |||
118 | /** |
||
119 | * |
||
120 | * Sets an input value on this fieldset. |
||
121 | * |
||
122 | * @param string $name The input name. |
||
123 | * |
||
124 | * @param mixed $value The input value. |
||
125 | * |
||
126 | * @return void |
||
127 | * |
||
128 | */ |
||
129 | public function __set($name, $value) |
||
133 | |||
134 | /** |
||
135 | * |
||
136 | * Checks if a value is set on an input in this fieldset. |
||
137 | * |
||
138 | * @param string $name The input name. |
||
139 | * |
||
140 | * @return bool |
||
141 | * |
||
142 | */ |
||
143 | public function __isset($name) |
||
151 | |||
152 | /** |
||
153 | * |
||
154 | * Sets the value of an input in this fieldset to null. |
||
155 | * |
||
156 | * @param string $name The input name. |
||
157 | * |
||
158 | * @return void |
||
159 | * |
||
160 | */ |
||
161 | public function __unset($name) |
||
167 | |||
168 | /** |
||
169 | * |
||
170 | * Returns the filter object. |
||
171 | * |
||
172 | * @return FilterInterface |
||
173 | * |
||
174 | */ |
||
175 | public function getFilter() |
||
179 | |||
180 | /** |
||
181 | * |
||
182 | * Returns an individual input object by name. |
||
183 | * |
||
184 | * @param string $name The name of the input object. |
||
185 | * |
||
186 | * @return AbstractInput |
||
187 | * |
||
188 | */ |
||
189 | public function getInput($name) |
||
190 | { |
||
191 | if (! isset($this->inputs[$name])) { |
||
192 | throw new Exception\NoSuchInput($name); |
||
193 | } |
||
194 | |||
195 | $input = $this->inputs[$name]; |
||
196 | $input->setNamePrefix($this->getFullName()); |
||
197 | return $input; |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * |
||
202 | * Returns the names of all input objects in this fieldset. |
||
203 | * |
||
204 | * @return array |
||
205 | * |
||
206 | */ |
||
207 | public function getInputNames() |
||
211 | |||
212 | /** |
||
213 | * |
||
214 | * Returns the input builder. |
||
215 | * |
||
216 | * @return BuilderInterface |
||
217 | * |
||
218 | */ |
||
219 | public function getBuilder() |
||
223 | |||
224 | /** |
||
225 | * |
||
226 | * Returns the options object |
||
227 | * |
||
228 | * @return mixed |
||
229 | * |
||
230 | */ |
||
231 | public function getOptions() |
||
235 | |||
236 | /** |
||
237 | * |
||
238 | * Fills this fieldset with input values. |
||
239 | * |
||
240 | * @param array $data The values for this fieldset. |
||
241 | * |
||
242 | * @return void |
||
243 | * |
||
244 | */ |
||
245 | public function fill(array $data) |
||
254 | |||
255 | /** |
||
256 | * |
||
257 | * Initializes the inputs and filter. |
||
258 | * |
||
259 | * @return void |
||
260 | * |
||
261 | */ |
||
262 | public function init() |
||
265 | |||
266 | /** |
||
267 | * |
||
268 | * Did the input data pass the filter rules? |
||
269 | * |
||
270 | * @return null|bool |
||
271 | * |
||
272 | */ |
||
273 | public function isSuccess() |
||
277 | |||
278 | /** |
||
279 | * |
||
280 | * Sets a new Field input. |
||
281 | * |
||
282 | * @param string $name The Field name. |
||
283 | * |
||
284 | * @param string $type A Field of this type; defaults to 'text'. |
||
285 | * |
||
286 | * @return Field |
||
287 | * |
||
288 | */ |
||
289 | public function setField($name, $type = null) |
||
294 | |||
295 | /** |
||
296 | * |
||
297 | * Sets a new Fieldset input. |
||
298 | * |
||
299 | * @param string $name The Fieldset name. |
||
300 | * |
||
301 | * @param string $type A Fieldset of this type; defaults to $name. |
||
302 | * |
||
303 | * @return Fieldset |
||
304 | * |
||
305 | */ |
||
306 | public function setFieldset($name, $type = null) |
||
311 | |||
312 | /** |
||
313 | * |
||
314 | * Sets a new Collection input. |
||
315 | * |
||
316 | * @param string $name The Collection name. |
||
317 | * |
||
318 | * @param string $type A Collection of this type of Fieldset; defaults to |
||
319 | * $name. |
||
320 | * |
||
321 | * @return Collection |
||
322 | * |
||
323 | */ |
||
324 | public function setCollection($name, $type = null) |
||
329 | |||
330 | /** |
||
331 | * |
||
332 | * Returns an input in a format suitable for a view. |
||
333 | * |
||
334 | * @param string $name The input name. |
||
335 | * |
||
336 | * @return mixed |
||
337 | * |
||
338 | */ |
||
339 | public function get($name = null) |
||
348 | |||
349 | /** |
||
350 | * |
||
351 | * Filters the inputs on this fieldset. |
||
352 | * |
||
353 | * @return bool True if all the filter rules pass, false if not. |
||
354 | * |
||
355 | */ |
||
356 | public function filter() |
||
384 | |||
385 | /** |
||
386 | * |
||
387 | * Returns the failures. |
||
388 | * |
||
389 | * @return ArrayObject |
||
390 | * |
||
391 | */ |
||
392 | public function getFailures() |
||
396 | |||
397 | /** |
||
398 | * |
||
399 | * Returns the value of this input for use in arrays. |
||
400 | * |
||
401 | * @return array |
||
402 | * |
||
403 | */ |
||
404 | public function getValue() |
||
412 | } |
||
413 |