http://www.mediawiki.org/wiki/Special:Code/MediaWiki/60383
Revision: 60383 Author: jeroendedauw Date: 2009-12-25 00:22:32 +0000 (Fri, 25 Dec 2009) Log Message: ----------- Changes for 0.2. See http://www.mediawiki.org/wiki/Extension:Validator#Version_0.2 Modified Paths: -------------- trunk/extensions/Validator/Validator.class.php trunk/extensions/Validator/Validator.php trunk/extensions/Validator/Validator_Functions.php Modified: trunk/extensions/Validator/Validator.class.php =================================================================== --- trunk/extensions/Validator/Validator.class.php 2009-12-25 00:22:02 UTC (rev 60382) +++ trunk/extensions/Validator/Validator.class.php 2009-12-25 00:22:32 UTC (rev 60383) @@ -50,7 +50,7 @@ * @var array Holder for the validation functions. */ private static $validationFunctions = array( - 'in_array' => 'in_array', + 'in_array' => array( 'ValidatorFunctions', 'in_array' ), 'in_range' => array( 'ValidatorFunctions', 'in_range' ), 'is_numeric' => 'is_numeric', 'is_integer' => array( 'ValidatorFunctions', 'is_integer' ), @@ -230,6 +230,7 @@ $this->parameterInfo[$name]['criteria']['is_numeric'] = array(); break; case 'boolean': + // TODO: work with list of true and false values. $this->parameterInfo[$name]['criteria']['in_array'] = array('yes', 'no', 'on', 'off'); break; case 'char': @@ -378,15 +379,9 @@ * * @return unknown_type */ - private function doCriteriaValidation($validationFunction, $value, $criteriaArgs) { - // TODO: argument buildup like output formats - - // Build up the array of parameters to be passed to call_user_func_array. - $arguments = array( $value ); - if ( count( $criteriaArgs ) > 0 ) $arguments[] = $criteriaArgs; - + private function doCriteriaValidation($validationFunction, $value, $criteriaArgs) { // Call the validation function and store the result. - return call_user_func_array( $validationFunction, $arguments ); + return call_user_func_array( $validationFunction, array_merge(array($value), $criteriaArgs) ); } /** Modified: trunk/extensions/Validator/Validator.php =================================================================== --- trunk/extensions/Validator/Validator.php 2009-12-25 00:22:02 UTC (rev 60382) +++ trunk/extensions/Validator/Validator.php 2009-12-25 00:22:32 UTC (rev 60383) @@ -24,7 +24,7 @@ die( 'Not an entry point.' ); } -define( 'Validator_VERSION', '0.2 a6' ); +define( 'Validator_VERSION', '0.2 a7' ); // Constants indicating the strictness of the parameter validation. define( 'Validator_ERRORS_NONE', 0 ); Modified: trunk/extensions/Validator/Validator_Functions.php =================================================================== --- trunk/extensions/Validator/Validator_Functions.php 2009-12-25 00:22:02 UTC (rev 60382) +++ trunk/extensions/Validator/Validator_Functions.php 2009-12-25 00:22:32 UTC (rev 60383) @@ -26,14 +26,17 @@ * Returns whether the provided value, which must be a number, is within a certain range. Upper bound not included. * * @param $value - * @param array $limits + * @param $lower + * @param $upper * * @return boolean */ - public static function in_range( $value, array $limits ) { + public static function in_range( $value, $lower = false, $upper = false ) { if ( ! is_numeric( $value ) ) return false; $value = (int)$value; - return ( $value >= $limits[0] && $value < $limits[1] ) || ( $value < $limits[0] And $value >= $limits[1] ); + if ($lower !== false && $value < $lower) return false; + if ($upper !== false && $value >= $upper) return false; + return true; } /** @@ -48,6 +51,19 @@ } /** + * Returns whether the string value is not empty. Not empty is defined as having at least one character after trimming. + * + * @param $value + * + * @return boolean + */ + public static function in_array( $value ) { + $params = func_get_args(); + array_shift( $params ); // Ommit the value + return in_array($value, $params); + } + + /** * Returns whether a variable is an integer or an integer string. Uses the native PHP function. * * @param $value @@ -62,24 +78,26 @@ * Returns whether the length of the value is within a certain range. Upper bound not included. * * @param string $value - * @param array $limits + * @param $lower + * @param $upper * * @return boolean */ - public static function has_length( $value, array $limits ) { - return self::in_range(strlen($value), $limits); + public static function has_length( $value, $lower = false, $upper = false ) { + return self::in_range(strlen($value), $lower, $upper); } /** * Returns whether the amount of items in the list is within a certain range. Upper bound not included. * * @param array $values - * @param $limits + * @param $lower + * @param $upper * * @return boolean */ - public static function has_item_count( array $values, array $limits ) { - return self::in_range(count($value), $limits); + public static function has_item_count( array $values, $lower = false, $upper = false ) { + return self::in_range(count($values), $lower, $upper); } /** _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs