1 | <?php |
||
14 | abstract class ValueValidatorBase implements ValueValidator { |
||
15 | |||
16 | /** |
||
17 | * A list of allowed values. This means the parameters value(s) must be in the list |
||
18 | * during validation. False for no restriction. |
||
19 | * |
||
20 | * @var array|false |
||
21 | */ |
||
22 | protected $allowedValues = false; |
||
23 | |||
24 | /** |
||
25 | * A list of prohibited values. This means the parameters value(s) must |
||
26 | * not be in the list during validation. False for no restriction. |
||
27 | * |
||
28 | * @var array|false |
||
29 | */ |
||
30 | protected $prohibitedValues = false; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $options = []; |
||
36 | |||
37 | /** |
||
38 | * @var Error[] |
||
39 | */ |
||
40 | protected $errors = []; |
||
41 | |||
42 | /** |
||
43 | * @see ValueValidator::validate |
||
44 | * |
||
45 | * @param mixed $value |
||
46 | * |
||
47 | * @return Result |
||
48 | */ |
||
49 | final public function validate( $value ) { |
||
64 | |||
65 | /** |
||
66 | * Checks the value against the allowed values and prohibited values lists in case they are set. |
||
67 | * |
||
68 | * @param mixed $value |
||
69 | */ |
||
70 | protected function valueIsAllowed( $value ) { |
||
79 | |||
80 | /** |
||
81 | * @see ValueValidator::validate |
||
82 | * |
||
83 | * @param mixed $value |
||
84 | */ |
||
85 | abstract public function doValidation( $value ); |
||
86 | |||
87 | /** |
||
88 | * Sets the parameter definition values contained in the provided array. |
||
89 | * @see ParamDefinition::setArrayValues |
||
90 | * |
||
91 | * @param array $param |
||
92 | */ |
||
93 | public function setOptions( array $param ) { |
||
106 | |||
107 | /** |
||
108 | * Registers an error message. |
||
109 | * |
||
110 | * @param string $errorMessage |
||
111 | */ |
||
112 | protected function addErrorMessage( $errorMessage ) { |
||
115 | |||
116 | /** |
||
117 | * Registers an error. |
||
118 | * |
||
119 | * @param Error $error |
||
120 | */ |
||
121 | protected function addError( Error $error ) { |
||
124 | |||
125 | /** |
||
126 | * Registers a list of errors. |
||
127 | * |
||
128 | * @param Error[] $errors |
||
129 | */ |
||
130 | protected function addErrors( array $errors ) { |
||
133 | |||
134 | /** |
||
135 | * Runs the value through the provided ValueValidator and registers the errors. |
||
136 | * Options of $this can be mapped to those of the passed ValueValidator using |
||
137 | * the $optionMap parameter in which keys are source names and values are target |
||
138 | * names. |
||
139 | * |
||
140 | * @param mixed $value |
||
141 | * @param ValueValidator $validator |
||
142 | * @param string|null $property |
||
143 | * @param array $optionMap |
||
144 | */ |
||
145 | protected function runSubValidator( |
||
170 | |||
171 | /** |
||
172 | * If the "values" and "excluding" arguments should be held into account. |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | protected function enableWhitelistRestrictions() { |
||
179 | |||
180 | /** |
||
181 | * Returns the allowed values. |
||
182 | * |
||
183 | * TODO: think about how to access set options in general and if we want to have |
||
184 | * whitelist and baclklist values in the validator objects to begin with. |
||
185 | * |
||
186 | * @return array|bool false |
||
187 | */ |
||
188 | public function getWhitelistedValues() { |
||
191 | |||
192 | } |
||
193 |