1 | <?php |
||
18 | class BaseElement extends \Fiv\Form\Element\Html { |
||
19 | |||
20 | /** |
||
21 | * @var null|boolean |
||
22 | */ |
||
23 | protected $validationResult = null; |
||
24 | |||
25 | /** |
||
26 | * @var \Fiv\Form\Validator\Base[] |
||
27 | */ |
||
28 | protected $validators = []; |
||
29 | |||
30 | /** |
||
31 | * @var \Fiv\Form\Filter\FilterInterface[] |
||
32 | */ |
||
33 | protected $filters = []; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $text = ''; |
||
39 | |||
40 | /** |
||
41 | * @var null|string |
||
42 | */ |
||
43 | protected $value = null; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Attach validator to current element |
||
48 | * |
||
49 | * @param \Fiv\Form\Validator\ValidatorInterface[]|\Fiv\Form\Validator\ValidatorInterface $validator |
||
50 | * @throws \Exception |
||
51 | * @return $this |
||
52 | */ |
||
53 | 6 | public function addValidator($validator) { |
|
67 | |||
68 | |||
69 | /** |
||
70 | * @param string $text |
||
71 | * @return $this |
||
72 | */ |
||
73 | 10 | public function setText($text) { |
|
77 | |||
78 | |||
79 | /** |
||
80 | * @return mixed |
||
81 | */ |
||
82 | public function getText() { |
||
85 | |||
86 | |||
87 | /** |
||
88 | * Attach filter to current element |
||
89 | * |
||
90 | * @param \Fiv\Form\Filter\FilterInterface|\Fiv\Form\Filter\FilterInterface[] $filter |
||
91 | * @throws \Exception |
||
92 | * @return $this |
||
93 | */ |
||
94 | 3 | public function addFilter($filter) { |
|
95 | 3 | if (!is_array($filter)) { |
|
96 | 1 | $filter = [$filter]; |
|
97 | } |
||
98 | 3 | foreach ($filter as $filterClass) { |
|
99 | 3 | if (!($filterClass instanceof FilterInterface)) { |
|
100 | throw new \Exception('Invalid filter class: ' . get_class($filterClass)); |
||
101 | } |
||
102 | 3 | $this->filters[] = $filterClass; |
|
103 | } |
||
104 | |||
105 | 3 | return $this; |
|
106 | } |
||
107 | |||
108 | |||
109 | /** |
||
110 | * Alias of setAttribute('value', $value) |
||
111 | * |
||
112 | * @param $value |
||
113 | * @return $this |
||
114 | */ |
||
115 | 2 | public function setValue($value) { |
|
119 | |||
120 | |||
121 | /** |
||
122 | * @inheritdoc |
||
123 | */ |
||
124 | 18 | public function setAttribute($name, $value) { |
|
140 | |||
141 | |||
142 | /** |
||
143 | * @return \Fiv\Form\Filter\FilterInterface[] |
||
144 | */ |
||
145 | 16 | public function getFilters() { |
|
148 | |||
149 | |||
150 | /** |
||
151 | * Return true if element is valid |
||
152 | * @return boolean |
||
153 | */ |
||
154 | 8 | public function validate() { |
|
171 | |||
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | 14 | public function getValue() { |
|
179 | |||
180 | |||
181 | /** |
||
182 | * @return \Fiv\Form\Validator\Base[] |
||
183 | */ |
||
184 | 8 | public function getValidators() { |
|
187 | |||
188 | |||
189 | /** |
||
190 | * @inheritdoc |
||
191 | */ |
||
192 | 3 | public function render() { |
|
197 | |||
198 | |||
199 | /** |
||
200 | * @return array |
||
201 | */ |
||
202 | public function getValidatorsErrors() { |
||
210 | |||
211 | |||
212 | /** |
||
213 | * @deprecated use addValidator(new \Fiv\Form\Validator\Required()) instead |
||
214 | * @see addValidator |
||
215 | * @return $this |
||
216 | */ |
||
217 | public function required() { |
||
221 | } |