Index: trunk/extensions/Validator/includes/ListParameter.php |
— | — | @@ -124,8 +124,13 @@ |
125 | 125 | public function validate() { |
126 | 126 | $this->validateListCriteria(); |
127 | 127 | |
128 | | - parent::validate(); |
| 128 | + $success = parent::doValidation(); |
129 | 129 | |
| 130 | + if ( !$success && count( $this->value ) == 0 ) { |
| 131 | + $this->value = (array)$this->default; |
| 132 | + } |
| 133 | + |
| 134 | + return $success; |
130 | 135 | // FIXME: it's possible the list criteria are not satisfied here anymore due to filtering of invalid items. |
131 | 136 | } |
132 | 137 | |
Index: trunk/extensions/Validator/includes/Parameter.php |
— | — | @@ -350,15 +350,30 @@ |
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
354 | | - * Validates the parameter value against it's criteria. |
355 | | - * If the parameter is invalid or not provided, it'll be set to it's default, |
356 | | - * or when it's required, a fatal error will be stored. |
| 354 | + * Validates the parameter value and sets the value to it's default when errors occur. |
357 | 355 | * |
358 | 356 | * @since 0.4 |
359 | 357 | * |
360 | | - * @return boolean If there where no fatal errors |
| 358 | + * @return boolean Indicates if there was any validation error |
361 | 359 | */ |
362 | 360 | public function validate() { |
| 361 | + $success = $this->doValidation(); |
| 362 | + |
| 363 | + if ( !$success ) { |
| 364 | + $this->value = $this->default; |
| 365 | + } |
| 366 | + |
| 367 | + return $success; |
| 368 | + } |
| 369 | + |
| 370 | + /** |
| 371 | + * Validates the parameter value. |
| 372 | + * |
| 373 | + * @since 0.4 |
| 374 | + * |
| 375 | + * @return boolean Indicates if there was any validation error |
| 376 | + */ |
| 377 | + protected function doValidation() { |
363 | 378 | if ( $this->setCount == 0 ) { |
364 | 379 | if ( $this->isRequired() ) { |
365 | 380 | // TODO: fatal error |
— | — | @@ -372,14 +387,8 @@ |
373 | 388 | else { |
374 | 389 | $this->value = $this->originalValue; |
375 | 390 | |
376 | | - list( $success, $hasError ) = $this->validateCriteria(); |
377 | | - |
378 | | - if ( $hasError ) { |
379 | | - $this->value = $this->default; |
380 | | - } |
381 | | - } |
382 | | - |
383 | | - return $success; |
| 391 | + $success = $this->validateCriteria(); |
| 392 | + } |
384 | 393 | } |
385 | 394 | |
386 | 395 | /** |
— | — | @@ -387,7 +396,7 @@ |
388 | 397 | * |
389 | 398 | * @since 0.4 |
390 | 399 | * |
391 | | - * @return boolean Indicates if there was any validation error. |
| 400 | + * @return boolean Indicates if there was any validation error |
392 | 401 | */ |
393 | 402 | protected function validateCriteria() { |
394 | 403 | $success = true; |