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 | 12 | public function __construct() |
|
38 | { |
||
39 | 12 | $fields = $this->fields(); |
|
40 | |||
41 | 12 | if (!is_array($fields) || empty($fields)) { |
|
42 | 1 | throw new ConfigurationException('form is not configured yet'); |
|
43 | } |
||
44 | |||
45 | 11 | $this->parseConfiguration($fields); |
|
46 | 10 | } |
|
47 | |||
48 | /** |
||
49 | * @return array |
||
50 | */ |
||
51 | abstract protected function fields(): array; |
||
52 | |||
53 | /** |
||
54 | * {@inheritDoc} |
||
55 | */ |
||
56 | public function setData(array $data) |
||
65 | |||
66 | /** |
||
67 | * {@inheritDoc} |
||
68 | */ |
||
69 | public function getData(): array |
||
75 | |||
76 | /** |
||
77 | * {@inheritDoc} |
||
78 | */ |
||
79 | 7 | public function handleRequest(RequestInterface $request) |
|
93 | |||
94 | /** |
||
95 | * {@inheritDoc} |
||
96 | */ |
||
97 | 2 | public function validate() |
|
107 | |||
108 | /** |
||
109 | * @param array $data |
||
110 | * @return AbstractForm |
||
111 | */ |
||
112 | 6 | protected function fetchRequestData(array $data) |
|
135 | |||
136 | /** |
||
137 | * @param array $fields |
||
138 | */ |
||
139 | 11 | private function parseConfiguration(array $fields) |
|
163 | |||
164 | /** |
||
165 | * Построение правил валидации на основе заданного конфига |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | 2 | private function buildValidationRules() |
|
185 | } |