1 | <?php |
||
19 | abstract class ValueValidatorBase implements ValueValidator { |
||
20 | |||
21 | /** |
||
22 | * A list of allowed values. This means the parameters value(s) must be in the list |
||
23 | * during validation. False for no restriction. |
||
24 | * |
||
25 | * @since 0.1 |
||
26 | * |
||
27 | * @var array|false |
||
28 | */ |
||
29 | protected $allowedValues = false; |
||
30 | |||
31 | /** |
||
32 | * A list of prohibited values. This means the parameters value(s) must |
||
33 | * not be in the list during validation. False for no restriction. |
||
34 | * |
||
35 | * @since 0.1 |
||
36 | * |
||
37 | * @var array|false |
||
38 | */ |
||
39 | protected $prohibitedValues = false; |
||
40 | |||
41 | /** |
||
42 | * @since 0.1 |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $options = []; |
||
47 | |||
48 | /** |
||
49 | * @since 0.1 |
||
50 | * |
||
51 | * @var Error[] |
||
52 | */ |
||
53 | protected $errors = []; |
||
54 | |||
55 | /** |
||
56 | * @see ValueValidator::validate |
||
57 | * |
||
58 | * @param mixed $value |
||
59 | * |
||
60 | * @return Result |
||
61 | */ |
||
62 | final public function validate( $value ) { |
||
77 | |||
78 | /** |
||
79 | * Checks the value against the allowed values and prohibited values lists in case they are set. |
||
80 | * |
||
81 | * @since 0.1 |
||
82 | * |
||
83 | * @param mixed $value |
||
84 | */ |
||
85 | protected function valueIsAllowed( $value ) { |
||
94 | |||
95 | /** |
||
96 | * @see ValueValidator::validate |
||
97 | * |
||
98 | * @since 0.1 |
||
99 | * |
||
100 | * @param mixed $value |
||
101 | */ |
||
102 | abstract public function doValidation( $value ); |
||
103 | |||
104 | /** |
||
105 | * Sets the parameter definition values contained in the provided array. |
||
106 | * @see ParamDefinition::setArrayValues |
||
107 | * |
||
108 | * @param array $param |
||
109 | */ |
||
110 | public function setOptions( array $param ) { |
||
123 | |||
124 | /** |
||
125 | * Registers an error message. |
||
126 | * |
||
127 | * @since 0.1 |
||
128 | * |
||
129 | * @param string $errorMessage |
||
130 | */ |
||
131 | protected function addErrorMessage( $errorMessage ) { |
||
134 | |||
135 | /** |
||
136 | * Registers an error. |
||
137 | * |
||
138 | * @since 0.1 |
||
139 | * |
||
140 | * @param Error $error |
||
141 | */ |
||
142 | protected function addError( Error $error ) { |
||
145 | |||
146 | /** |
||
147 | * Registers a list of errors. |
||
148 | * |
||
149 | * @since 0.1 |
||
150 | * |
||
151 | * @param Error[] $errors |
||
152 | */ |
||
153 | protected function addErrors( array $errors ) { |
||
156 | |||
157 | /** |
||
158 | * Runs the value through the provided ValueValidator and registers the errors. |
||
159 | * Options of $this can be mapped to those of the passed ValueValidator using |
||
160 | * the $optionMap parameter in which keys are source names and values are target |
||
161 | * names. |
||
162 | * |
||
163 | * @since 0.1 |
||
164 | * |
||
165 | * @param mixed $value |
||
166 | * @param ValueValidator $validator |
||
167 | * @param string|null $property |
||
168 | * @param array $optionMap |
||
169 | */ |
||
170 | protected function runSubValidator( |
||
195 | |||
196 | /** |
||
197 | * If the "values" and "excluding" arguments should be held into account. |
||
198 | * |
||
199 | * @since 0.1 |
||
200 | * |
||
201 | * @return bool |
||
202 | */ |
||
203 | protected function enableWhitelistRestrictions() { |
||
206 | |||
207 | /** |
||
208 | * Returns the allowed values. |
||
209 | * |
||
210 | * TODO: think about how to access set options in general and if we want to have |
||
211 | * whitelist and baclklist values in the validator objects to begin with. |
||
212 | * |
||
213 | * @since 0.1 |
||
214 | * |
||
215 | * @return array|bool false |
||
216 | */ |
||
217 | public function getWhitelistedValues() { |
||
220 | |||
221 | } |
||
222 |