1 | <?php |
||
15 | abstract class AbstractForm implements FormInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $data = []; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $types = []; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $validators = []; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $cleanup = []; |
||
36 | |||
37 | 14 | public function __construct() |
|
38 | { |
||
39 | 14 | $fields = $this->fields(); |
|
40 | |||
41 | 14 | if (!is_array($fields) || empty($fields)) { |
|
42 | 1 | throw new ConfigurationException('form is not configured yet'); |
|
43 | } |
||
44 | |||
45 | 13 | $this->parseConfiguration($fields); |
|
46 | 12 | } |
|
47 | |||
48 | /** |
||
49 | * @return static |
||
50 | */ |
||
51 | 1 | public static function create() |
|
52 | { |
||
53 | 1 | return new static; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return array |
||
58 | */ |
||
59 | abstract protected function fields(): array; |
||
60 | |||
61 | /** |
||
62 | * {@inheritDoc} |
||
63 | */ |
||
64 | public function setData(array $data) |
||
73 | |||
74 | /** |
||
75 | * {@inheritDoc} |
||
76 | */ |
||
77 | public function getData(): array |
||
83 | |||
84 | /** |
||
85 | * {@inheritDoc} |
||
86 | */ |
||
87 | 7 | public function handleRequest(RequestInterface $request) |
|
101 | |||
102 | /** |
||
103 | * {@inheritDoc} |
||
104 | */ |
||
105 | 3 | public function validate() |
|
116 | |||
117 | /** |
||
118 | * @param array $data |
||
119 | * @return AbstractForm |
||
120 | */ |
||
121 | 6 | protected function fetchRequestData(array $data) |
|
144 | |||
145 | /** |
||
146 | * @param array $fields |
||
147 | */ |
||
148 | private function parseConfiguration(array $fields) |
||
161 | |||
162 | /** |
||
163 | * @param string $field |
||
164 | * @param array $config |
||
165 | * |
||
166 | * @throws ConfigurationException |
||
167 | */ |
||
168 | 13 | private function assertFieldConfigHasValidators(string $field, array $config) |
|
174 | |||
175 | /** |
||
176 | * @return array |
||
177 | */ |
||
178 | 3 | private function buildValidationRules(): array |
|
194 | |||
195 | /** |
||
196 | * @return array |
||
197 | */ |
||
198 | 3 | private function buildCustomValidationMessages(): array |
|
212 | } |