r73380 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73379‎ | r73380 | r73381 >
Date:14:34, 20 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.4 - added parameter type based criteria and made a small improvement to the inArray criteria constructor
Modified paths:
  • /trunk/extensions/Validator/includes/Parameter.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionInArray.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/criteria/CriterionInArray.php
@@ -29,10 +29,20 @@
3030 *
3131 * @since 0.4
3232 */
33 - public function __construct( $allowedValues ) {
 33+ public function __construct() {
3434 parent::__construct();
3535
36 - $this->allowedValues = (array)$allowedValues;
 36+ $args = func_get_args();
 37+
 38+ if ( count( $args ) > 1 ) {
 39+ $this->allowedValues = $args;
 40+ }
 41+ elseif ( count( $args ) == 1 ) {
 42+ $this->allowedValues = (array)$args[0];
 43+ }
 44+ else {
 45+ $this->allowedValues = array();
 46+ }
3747 }
3848
3949 /**
Index: trunk/extensions/Validator/includes/Parameter.php
@@ -535,30 +535,27 @@
536536 protected function getCriteriaForType() {
537537 $criteria = array();
538538
539 - /* TODO
540539 switch( $this->type ) {
541 - case TYPE_INTEGER:
542 - $criteria[] = 'is_integer';
 540+ case self::TYPE_INTEGER:
 541+ $criteria[] = new CriterionIsInteger();
543542 break;
544 - case TYPE_FLOAT:
545 - $criteria[] = 'is_float';
 543+ case self::TYPE_FLOAT:
 544+ $criteria[] = new CriterionIsFloat();
546545 break;
547 - case TYPE_NUMBER: // Note: This accepts non-decimal notations!
548 - $criteria[] = 'is_numeric';
 546+ case self::TYPE_FLOAT: // Note: This accepts non-decimal notations!
 547+ $criteria[] = new CriterionIsNumeric();
549548 break;
550 - case TYPE_BOOLEAN:
551 - // TODO: work with list of true and false values.
552 - // TODO: i18n
553 - $criteria[] = array( 'in_array' => array( 'yes', 'no', 'on', 'off' ) );
 549+ case self::TYPE_BOOLEAN:
 550+ // TODO: work with list of true and false values and i18n.
 551+ $criteria[] = new CriterionInArray( 'yes', 'no', 'on', 'off' );
554552 break;
555 - case TYPE_CHAR:
556 - $criteria[] = array( 'has_length' => array( 1, 1 ) );
 553+ case self::TYPE_CHAR:
 554+ $criteria[] = new CriterionHasLength( 1, 1 );
557555 break;
558 - case TYPE_STRING: default:
 556+ case self::TYPE_STRING: default:
559557 // No extra criteria for strings.
560558 break;
561559 }
562 - */
563560
564561 return $criteria;
565562 }
@@ -571,7 +568,6 @@
572569 * @return array
573570 */
574571 public function getListCriteria() {
575 - // TODO
576572 return array();
577573 }
578574

Status & tagging log