1 | <?php |
||
22 | abstract class AbstractForm implements FormInterface, Iterator |
||
23 | { |
||
24 | /** @var NestedElementInterface */ |
||
25 | protected $form; |
||
26 | /** @var string */ |
||
27 | protected $salt; |
||
28 | |||
29 | // The implementation of the Iterator interface. |
||
30 | use IteratorTrait; |
||
31 | // CamelCase to under_score converter |
||
32 | use CamelCaseToUnderScoreTrait; |
||
33 | |||
34 | /** |
||
35 | * AbstractForm constructor. |
||
36 | * |
||
37 | * @param string $name |
||
38 | * @param string $action |
||
39 | * @param string $method |
||
40 | */ |
||
41 | 8 | final public function __construct($name = '', $action = '', $method = 'POST') |
|
64 | |||
65 | /** |
||
66 | * Returns the form container element. E.g.: for HTML forms it is the <form> tag. |
||
67 | * |
||
68 | * @return NestedElementInterface |
||
69 | */ |
||
70 | abstract protected function getFormContainer(); |
||
71 | |||
72 | /** |
||
73 | * Initialize form. |
||
74 | * |
||
75 | * @return void |
||
76 | */ |
||
77 | abstract protected function initForm(); |
||
78 | |||
79 | /** |
||
80 | * Sets form name. |
||
81 | * |
||
82 | * @param string $name |
||
83 | * @return FormInterface |
||
84 | */ |
||
85 | 2 | public function setName($name) |
|
95 | |||
96 | /** |
||
97 | * Gets form name. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 3 | public function getName() |
|
105 | |||
106 | /** |
||
107 | * Set unique identifier for the form. |
||
108 | * |
||
109 | * @param string $salt |
||
110 | * @return AbstractForm |
||
111 | */ |
||
112 | 3 | public function setNameSalt($salt) |
|
118 | |||
119 | /** |
||
120 | * Sets form action. |
||
121 | * |
||
122 | * @param string $action |
||
123 | * @return AbstractForm |
||
124 | */ |
||
125 | 1 | final public function setAction($action) |
|
131 | |||
132 | /** |
||
133 | * Sets form submit. |
||
134 | * |
||
135 | * @param string $method |
||
136 | * @return AbstractForm |
||
137 | */ |
||
138 | 1 | final public function setMethod($method = 'POST') |
|
144 | |||
145 | /** |
||
146 | * Sets form encoding type. |
||
147 | * |
||
148 | * @param string $encodingType |
||
149 | * @return AbstractForm |
||
150 | */ |
||
151 | 1 | final protected function setEnctype($encodingType = 'application/x-www-form-urlencoded') |
|
157 | |||
158 | /** |
||
159 | * Sets form auto-complete option. |
||
160 | * |
||
161 | * @param bool $autoComplete |
||
162 | * @return AbstractForm |
||
163 | */ |
||
164 | 3 | final public function setAutoComplete($autoComplete = true) |
|
185 | |||
186 | /** |
||
187 | * Sets specific form attributes. |
||
188 | * |
||
189 | * @param $name |
||
190 | * @param $value |
||
191 | */ |
||
192 | 4 | private function setAttribute($name, $value) |
|
199 | |||
200 | /** |
||
201 | * Adds a form element to the form. |
||
202 | * |
||
203 | * @param array<FormElementInterface> $nodes |
||
204 | * @return AbstractForm |
||
205 | */ |
||
206 | 8 | protected function setNodes(array $nodes) |
|
212 | |||
213 | /** |
||
214 | * Gets the form elements. |
||
215 | * |
||
216 | * @return array<FormElementInterface> |
||
217 | */ |
||
218 | 1 | protected function getNodes() |
|
222 | |||
223 | /** |
||
224 | * Validates the form. |
||
225 | * |
||
226 | * @param bool $reValidate |
||
227 | * @return bool |
||
228 | */ |
||
229 | 2 | public function isValid($reValidate = false) |
|
233 | |||
234 | /** |
||
235 | * Gets validation errors. |
||
236 | * |
||
237 | * @return array |
||
238 | */ |
||
239 | 1 | public function getErrors() |
|
243 | |||
244 | /** |
||
245 | * Sets form data. |
||
246 | * |
||
247 | * @param array $data |
||
248 | * @return FormInterface |
||
249 | */ |
||
250 | 1 | public function setData(array $data) |
|
260 | |||
261 | /** |
||
262 | * Returns the form data. |
||
263 | * |
||
264 | * @return array |
||
265 | */ |
||
266 | 1 | public function getData() |
|
270 | } |
||
271 |