Index: trunk/extensions/Validator/includes/Parameter.php |
— | — | @@ -17,6 +17,7 @@ |
18 | 18 | const TYPE_STRING = 'string'; |
19 | 19 | const TYPE_NUMBER = 'number'; |
20 | 20 | const TYPE_INTEGER = 'integer'; |
| 21 | + const TYPE_FLOAT = 'float'; |
21 | 22 | const TYPE_BOOLEAN = 'boolean'; |
22 | 23 | const TYPE_CHAR = 'char'; |
23 | 24 | |
— | — | @@ -105,6 +106,7 @@ |
106 | 107 | |
107 | 108 | /** |
108 | 109 | * 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. |
109 | 111 | * |
110 | 112 | * @since 0.4 |
111 | 113 | * |
— | — | @@ -243,7 +245,7 @@ |
244 | 246 | * @return string |
245 | 247 | */ |
246 | 248 | public function getListDelimeter() { |
247 | | - if ( $this->isList ) { |
| 249 | + if ( $this->isList() ) { |
248 | 250 | return count( $this->type ) > 1 ? $this->type[1] : self::$defaultListDelimeter; |
249 | 251 | } |
250 | 252 | else { |
— | — | @@ -259,33 +261,45 @@ |
260 | 262 | * @return array |
261 | 263 | */ |
262 | 264 | 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(); |
265 | 277 | |
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; |
288 | 300 | } |
289 | | - */ |
| 301 | + */ |
| 302 | + |
| 303 | + return $criteria; |
290 | 304 | } |
291 | 305 | |
292 | 306 | /** |