1 | <?php /** MicroFormBuilder */ |
||
21 | class FormBuilder |
||
22 | { |
||
23 | /** @var FormWidget $widget widget for render */ |
||
24 | protected $widget; |
||
25 | /** @var Form $form generator for elements */ |
||
26 | protected $form; |
||
27 | /** @var array $config config array */ |
||
28 | private $config; |
||
29 | /** @var IFormModel $model model for get data */ |
||
30 | private $model; |
||
31 | |||
32 | |||
33 | /** |
||
34 | * Constructor object |
||
35 | * |
||
36 | * @access public |
||
37 | * |
||
38 | * @param array $config |
||
39 | * @param IFormModel $model |
||
40 | * @param string $method method of request |
||
41 | * @param string $type type data |
||
42 | * @param string $action path URL action |
||
43 | * @param array $attr attributes for form |
||
44 | * |
||
45 | * @result void |
||
46 | * @throws \Micro\Base\Exception |
||
47 | */ |
||
48 | public function __construct( |
||
66 | |||
67 | /** |
||
68 | * Set model data |
||
69 | * |
||
70 | * Loading data in model from array |
||
71 | * |
||
72 | * @access public |
||
73 | * |
||
74 | * @param array $data array to change |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | public function setModelData(array $data = []) |
||
82 | |||
83 | /** |
||
84 | * Validation model |
||
85 | * |
||
86 | * @access public |
||
87 | * |
||
88 | * @return bool |
||
89 | * @throws \Micro\Base\Exception |
||
90 | */ |
||
91 | public function validateModel() |
||
95 | |||
96 | /** |
||
97 | * Getting model |
||
98 | * |
||
99 | * @access public |
||
100 | * @return \Micro\Mvc\Models\Model |
||
101 | */ |
||
102 | public function getModel() |
||
106 | |||
107 | /** |
||
108 | * Convert object to string |
||
109 | * |
||
110 | * @access public |
||
111 | * @return string |
||
112 | * @throws \Micro\Base\Exception |
||
113 | */ |
||
114 | public function __toString() |
||
118 | |||
119 | /** |
||
120 | * Render form builder |
||
121 | * |
||
122 | * @access public |
||
123 | * @return string |
||
124 | */ |
||
125 | public function render() |
||
139 | |||
140 | /** |
||
141 | * Render form heading |
||
142 | * |
||
143 | * @access public |
||
144 | * @return void |
||
145 | */ |
||
146 | public function beginRender() |
||
168 | |||
169 | /** |
||
170 | * Get errors from model |
||
171 | * |
||
172 | * @access public |
||
173 | * @return array |
||
174 | */ |
||
175 | public function getModelErrors() |
||
179 | |||
180 | /** |
||
181 | * Render form elements |
||
182 | * |
||
183 | * @access public |
||
184 | * |
||
185 | * @param null|array $conf configuration array |
||
186 | * |
||
187 | * @return void |
||
188 | * @throws \Micro\Base\Exception |
||
189 | */ |
||
190 | public function contentRender($conf = null) |
||
215 | |||
216 | /** |
||
217 | * Finish form render |
||
218 | * |
||
219 | * @access public |
||
220 | * @return void |
||
221 | */ |
||
222 | public function endRender() |
||
229 | } |
||
230 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: