1 | <?php |
||
22 | class FormElement implements Iterator |
||
23 | { |
||
24 | const TAG_INPUT_TEXT = 'text'; |
||
25 | const TAG_INPUT_PASSWORD = 'password'; |
||
26 | const TAG_FIELDSET = 'fieldset'; |
||
27 | const TAG_BUTTON_SUBMIT = 'submit'; |
||
28 | const TAG_BUTTON_RESET = 'reset'; |
||
29 | const TAG_BUTTON = 'button'; |
||
30 | |||
31 | /** @var int */ |
||
32 | protected static $tabIndex = 1; |
||
33 | /** @var string */ |
||
34 | private $tagName; |
||
35 | /** @var string */ |
||
36 | private $name; |
||
37 | /** @var string */ |
||
38 | private $label; |
||
39 | /** @var mixed */ |
||
40 | private $value; |
||
41 | /** @var array */ |
||
42 | private $attributes; |
||
43 | /** @var FormElement */ |
||
44 | private $parentNode; |
||
45 | /** @var FormElement[] */ |
||
46 | private $childNodes; |
||
47 | /** @var FormValidatorInterface[] */ |
||
48 | private $validators; |
||
49 | |||
50 | /** |
||
51 | * FormElement constructor. |
||
52 | * |
||
53 | * @param string $tagName |
||
54 | * @param string $name |
||
55 | * @param string $label |
||
56 | */ |
||
57 | public function __construct($tagName, $name, $label = '') |
||
64 | |||
65 | /** |
||
66 | * Returns the element tag name. |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function getTagName() |
||
74 | |||
75 | /** |
||
76 | * Sets parent element name |
||
77 | * |
||
78 | * @param FormElement $formElement |
||
79 | * @return FormElement |
||
80 | */ |
||
81 | public function setParentNode(FormElement $formElement) |
||
87 | |||
88 | /** |
||
89 | * Returns the element name. |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | public function getName() |
||
101 | |||
102 | /** |
||
103 | * Returns the element label. |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getLabel() |
||
111 | |||
112 | /** |
||
113 | * Sets element value. |
||
114 | * |
||
115 | * @param mixed $value |
||
116 | * @return FormElement |
||
117 | */ |
||
118 | public function setValue($value) |
||
124 | |||
125 | /** |
||
126 | * Returns element value. |
||
127 | * |
||
128 | * @return mixed |
||
129 | */ |
||
130 | public function getValue() |
||
134 | |||
135 | /** |
||
136 | * Set child node for the element. |
||
137 | * |
||
138 | * @param FormElement $childNode |
||
139 | * @return FormElement |
||
140 | */ |
||
141 | public function addChildNode(FormElement $childNode) |
||
149 | |||
150 | /** |
||
151 | * Gets the child nodes of the element. |
||
152 | * |
||
153 | * @return FormElement[] |
||
154 | */ |
||
155 | public function getChildNodes() |
||
159 | |||
160 | /** |
||
161 | * Sets element attribute. |
||
162 | * |
||
163 | * @param string $key |
||
164 | * @param string $value |
||
165 | * @throws InvalidArgumentException |
||
166 | * @return FormElement |
||
167 | */ |
||
168 | public function setAttribute($key, $value) |
||
182 | |||
183 | /** |
||
184 | * Sets multiple attributes. |
||
185 | * |
||
186 | * @param array $attributes |
||
187 | * @return FormElement |
||
188 | */ |
||
189 | public function setAttributes(array $attributes) |
||
197 | |||
198 | /** |
||
199 | * Gets element attribute. |
||
200 | * |
||
201 | * @param string $name |
||
202 | * @return mixed |
||
203 | */ |
||
204 | public function getAttribute($name) |
||
212 | |||
213 | /** |
||
214 | * Gets all the attributes. |
||
215 | * |
||
216 | * @return array |
||
217 | */ |
||
218 | public function getAttributes() |
||
222 | |||
223 | /** |
||
224 | * Adds validator to the form. |
||
225 | * |
||
226 | * @param FormValidatorInterface $validator |
||
227 | * @return FormElement |
||
228 | */ |
||
229 | public function addValidator(FormValidatorInterface $validator) |
||
235 | |||
236 | /** |
||
237 | * Validates element value. |
||
238 | * |
||
239 | * @return bool |
||
240 | */ |
||
241 | public function isValid() |
||
251 | |||
252 | /** |
||
253 | * Return the current element. |
||
254 | * |
||
255 | * @return FormElement |
||
256 | */ |
||
257 | final public function current() |
||
261 | |||
262 | /** |
||
263 | * Moves the pointer forward to next element. |
||
264 | * |
||
265 | * @return void |
||
266 | */ |
||
267 | final public function next() |
||
271 | |||
272 | /** |
||
273 | * Returns the key of the current element. |
||
274 | * |
||
275 | * @return mixed |
||
276 | */ |
||
277 | final public function key() |
||
281 | |||
282 | /** |
||
283 | * Checks if current position is valid. |
||
284 | * |
||
285 | * @return boolean |
||
286 | */ |
||
287 | final public function valid() |
||
293 | |||
294 | /** |
||
295 | * Rewinds the Iterator to the first element. |
||
296 | * |
||
297 | * @return void |
||
298 | */ |
||
299 | final public function rewind() |
||
303 | } |
||
304 | |||
305 |