1 | <?php |
||
13 | abstract class ValueValidatorObject implements ValueValidator { |
||
14 | |||
15 | /** |
||
16 | * A list of allowed values. This means the parameters value(s) must be in the list |
||
17 | * during validation. False for no restriction. |
||
18 | * |
||
19 | * @since 0.1 |
||
20 | * |
||
21 | * @var array|false |
||
22 | */ |
||
23 | protected $allowedValues = false; |
||
24 | |||
25 | /** |
||
26 | * A list of prohibited values. This means the parameters value(s) must |
||
27 | * not be in the list during validation. False for no restriction. |
||
28 | * |
||
29 | * @since 0.1 |
||
30 | * |
||
31 | * @var array|false |
||
32 | */ |
||
33 | protected $prohibitedValues = false; |
||
34 | |||
35 | /** |
||
36 | * @since 0.1 |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $options = []; |
||
41 | |||
42 | /** |
||
43 | * @since 0.1 |
||
44 | * |
||
45 | * @var Error[] |
||
46 | */ |
||
47 | protected $errors = []; |
||
48 | |||
49 | /** |
||
50 | * @see ValueValidator::validate |
||
51 | * |
||
52 | * @param mixed $value |
||
53 | * |
||
54 | * @return Result |
||
55 | */ |
||
56 | final public function validate( $value ) { |
||
71 | |||
72 | /** |
||
73 | * Checks the value against the allowed values and prohibited values lists in case they are set. |
||
74 | * |
||
75 | * @since 0.1 |
||
76 | * |
||
77 | * @param mixed $value |
||
78 | */ |
||
79 | protected function valueIsAllowed( $value ) { |
||
88 | |||
89 | /** |
||
90 | * @see ValueValidator::validate |
||
91 | * |
||
92 | * @since 0.1 |
||
93 | * |
||
94 | * @param mixed $value |
||
95 | */ |
||
96 | abstract public function doValidation( $value ); |
||
97 | |||
98 | /** |
||
99 | * Sets the parameter definition values contained in the provided array. |
||
100 | * @see ParamDefinition::setArrayValues |
||
101 | * |
||
102 | * @param array $param |
||
103 | */ |
||
104 | public function setOptions( array $param ) { |
||
117 | |||
118 | /** |
||
119 | * Registers an error message. |
||
120 | * |
||
121 | * @since 0.1 |
||
122 | * |
||
123 | * @param string $errorMessage |
||
124 | */ |
||
125 | protected function addErrorMessage( $errorMessage ) { |
||
128 | |||
129 | /** |
||
130 | * Registers an error. |
||
131 | * |
||
132 | * @since 0.1 |
||
133 | * |
||
134 | * @param Error $error |
||
135 | */ |
||
136 | protected function addError( Error $error ) { |
||
139 | |||
140 | /** |
||
141 | * Registers a list of errors. |
||
142 | * |
||
143 | * @since 0.1 |
||
144 | * |
||
145 | * @param Error[] $errors |
||
146 | */ |
||
147 | protected function addErrors( array $errors ) { |
||
150 | |||
151 | /** |
||
152 | * Runs the value through the provided ValueValidator and registers the errors. |
||
153 | * |
||
154 | * @since 0.3 |
||
155 | * |
||
156 | * @param mixed $value |
||
157 | * @param ValueValidator $validator |
||
158 | * @param string|null $property |
||
159 | */ |
||
160 | protected function runSubValidator( $value, ValueValidator $validator, $property = null ) { |
||
165 | |||
166 | /** |
||
167 | * If the "values" and "excluding" arguments should be held into account. |
||
168 | * |
||
169 | * @since 0.1 |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | protected function enableWhitelistRestrictions() { |
||
176 | |||
177 | /** |
||
178 | * Returns the allowed values. |
||
179 | * |
||
180 | * TODO: think about how to access set options in general and if we want to have |
||
181 | * whitelist and baclklist values in the validator objects to begin with. |
||
182 | * |
||
183 | * @since 0.1 |
||
184 | * |
||
185 | * @return array|bool false |
||
186 | */ |
||
187 | public function getWhitelistedValues() { |
||
190 | |||
191 | } |
||
192 |