r72417 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72416‎ | r72417 | r72418 >
Date:13:03, 5 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Implemented CriterionHasLength validation
Modified paths:
  • /trunk/extensions/Validator/includes/criteria/CriterionHasLength.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/criteria/CriterionHasLength.php
@@ -13,20 +13,31 @@
1414 */
1515 class CriterionHasLength extends ParameterCriterion {
1616
 17+ protected $lowerBound;
 18+ protected $upperBound;
 19+
1720 /**
1821 * Constructor.
1922 *
2023 * @since 0.4
2124 */
22 - public function __construct( ) {
 25+ public function __construct( $lowerBound, $upperBound = false ) {
2326 parent::__construct();
 27+
 28+ $this->lowerBound = $lowerBound;
 29+ $this->upperBound = $upperBound === false ? $lowerBound : $upperBound;
2430 }
2531
2632 /**
2733 * @see ParameterCriterion::validate
2834 */
2935 public function validate( $value ) {
 36+ $strlen = strlen( $value );
3037
 38+ if ( $strlen > $this->upperBound ) return false;
 39+ if ( $strlen < $this->lowerBound ) return false;
 40+
 41+ return true;
3142 }
3243
3344 }
\ No newline at end of file

Status & tagging log