r72404 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72403‎ | r72404 | r72405 >
Date:09:44, 5 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.4 - work on criteria handling in parameter class
Modified paths:
  • /trunk/extensions/Validator/includes/Parameter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/Parameter.php
@@ -17,6 +17,7 @@
1818 const TYPE_STRING = 'string';
1919 const TYPE_NUMBER = 'number';
2020 const TYPE_INTEGER = 'integer';
 21+ const TYPE_FLOAT = 'float';
2122 const TYPE_BOOLEAN = 'boolean';
2223 const TYPE_CHAR = 'char';
2324
@@ -105,6 +106,7 @@
106107
107108 /**
108109 * Returns a new instance of Parameter by converting a Validator 3.x-style parameter array definition.
 110+ * Note: this method is for backward compatibility and should not be used in new code.
109111 *
110112 * @since 0.4
111113 *
@@ -243,7 +245,7 @@
244246 * @return string
245247 */
246248 public function getListDelimeter() {
247 - if ( $this->isList ) {
 249+ if ( $this->isList() ) {
248250 return count( $this->type ) > 1 ? $this->type[1] : self::$defaultListDelimeter;
249251 }
250252 else {
@@ -259,33 +261,45 @@
260262 * @return array
261263 */
262264 public function getCriteria() {
263 - // TODO: type criteria resolving
264 - return $this->criteria;
 265+ return array_merge( $this->getCriteriaForType(), $this->criteria );
 266+ }
 267+
 268+ /**
 269+ * Gets the criteria for the type of the parameter.
 270+ *
 271+ * @since 0.4
 272+ *
 273+ * @return array
 274+ */
 275+ protected function getCriteriaForType() {
 276+ $criteria = array();
265277
266 - /*
267 - if ( array_key_exists( 'type', $this->mParameterInfo[$name] ) ) {
268 - // Add type specific criteria.
269 - switch( strtolower( $this->mParameterInfo[$name]['type'][0] ) ) {
270 - case 'integer':
271 - $this->addTypeCriteria( $name, 'is_integer' );
272 - break;
273 - case 'float':
274 - $this->addTypeCriteria( $name, 'is_float' );
275 - break;
276 - case 'number': // Note: This accepts non-decimal notations!
277 - $this->addTypeCriteria( $name, 'is_numeric' );
278 - break;
279 - case 'boolean':
280 - // TODO: work with list of true and false values.
281 - // TODO: i18n
282 - $this->addTypeCriteria( $name, 'in_array', array( 'yes', 'no', 'on', 'off' ) );
283 - break;
284 - case 'char':
285 - $this->addTypeCriteria( $name, 'has_length', array( 1, 1 ) );
286 - break;
287 - }
 278+ /* TODO
 279+ switch( $this->type ) {
 280+ case TYPE_INTEGER:
 281+ $criteria[] = 'is_integer';
 282+ break;
 283+ case TYPE_FLOAT:
 284+ $criteria[] = 'is_float';
 285+ break;
 286+ case TYPE_NUMBER: // Note: This accepts non-decimal notations!
 287+ $criteria[] = 'is_numeric';
 288+ break;
 289+ case TYPE_BOOLEAN:
 290+ // TODO: work with list of true and false values.
 291+ // TODO: i18n
 292+ $criteria[] = array( 'in_array' => array( 'yes', 'no', 'on', 'off' ) );
 293+ break;
 294+ case TYPE_CHAR:
 295+ $criteria[] = array( 'has_length' => array( 1, 1 ) );
 296+ break;
 297+ case TYPE_STRING: default:
 298+ // No extra criteria for strings.
 299+ break;
288300 }
289 - */
 301+ */
 302+
 303+ return $criteria;
290304 }
291305
292306 /**

Status & tagging log