Index: trunk/extensions/Validator/includes/ListParameterCriterion.php |
— | — | @@ -0,0 +1,26 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * List parameter criterion definition class. This is for criteria |
| 6 | + * that apply to list parameters as a whole instead of to their |
| 7 | + * individual items. |
| 8 | + * |
| 9 | + * @since 0.4 |
| 10 | + * |
| 11 | + * @file ListParameterCriterion.php |
| 12 | + * @ingroup Validator |
| 13 | + * @ingroup Criteria |
| 14 | + * |
| 15 | + * @author Jeroen De Dauw |
| 16 | + */ |
| 17 | +abstract class ListParameterCriterion extends ParameterCriterion { |
| 18 | + |
| 19 | + /** |
| 20 | + * Constructor. |
| 21 | + * |
| 22 | + * @since 0.4 |
| 23 | + */ |
| 24 | + public function __construct() { |
| 25 | + parent::__construct(); |
| 26 | + } |
| 27 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Validator/includes/ListParameterCriterion.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 28 | + native |
Index: trunk/extensions/Validator/includes/criteria/CriterionItemCount.php |
— | — | @@ -0,0 +1,42 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Parameter criterion stating that the value must have a certain length. |
| 6 | + * |
| 7 | + * @since 0.4 |
| 8 | + * |
| 9 | + * @file CriterionHasLength.php |
| 10 | + * @ingroup Validator |
| 11 | + * @ingroup Criteria |
| 12 | + * |
| 13 | + * @author Jeroen De Dauw |
| 14 | + */ |
| 15 | +class CriterionHasLength extends ListParameterCriterion { |
| 16 | + |
| 17 | + protected $lowerBound; |
| 18 | + protected $upperBound; |
| 19 | + |
| 20 | + /** |
| 21 | + * Constructor. |
| 22 | + * |
| 23 | + * @param integer $lowerBound |
| 24 | + * @param mixed $upperBound |
| 25 | + * |
| 26 | + * @since 0.4 |
| 27 | + */ |
| 28 | + public function __construct( $lowerBound, $upperBound = false ) { |
| 29 | + parent::__construct(); |
| 30 | + |
| 31 | + $this->lowerBound = $lowerBound; |
| 32 | + $this->upperBound = $upperBound === false ? $lowerBound : $upperBound; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @see ParameterCriterion::validate |
| 37 | + */ |
| 38 | + public function validate( array $values ) { |
| 39 | + $count = count( $values ); |
| 40 | + return $count <= $this->upperBound && $count >= $this->lowerBound; |
| 41 | + } |
| 42 | + |
| 43 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Validator/includes/criteria/CriterionItemCount.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 44 | + native |
Index: trunk/extensions/Validator/includes/criteria/CriterionUniqueItems.php |
— | — | @@ -0,0 +1,32 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Parameter criterion stating that the value must have a certain length. |
| 6 | + * |
| 7 | + * @since 0.4 |
| 8 | + * |
| 9 | + * @file CriterionHasLength.php |
| 10 | + * @ingroup Validator |
| 11 | + * @ingroup Criteria |
| 12 | + * |
| 13 | + * @author Jeroen De Dauw |
| 14 | + */ |
| 15 | +class CriterionHasLength extends ListParameterCriterion { |
| 16 | + |
| 17 | + /** |
| 18 | + * Constructor. |
| 19 | + * |
| 20 | + * @since 0.4 |
| 21 | + */ |
| 22 | + public function __construct() { |
| 23 | + parent::__construct(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @see ParameterCriterion::validate |
| 28 | + */ |
| 29 | + public function validate( array $values ) { |
| 30 | + return count( $values ) == count( array_unique( $values ) ); |
| 31 | + } |
| 32 | + |
| 33 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Validator/includes/criteria/CriterionUniqueItems.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 34 | + native |
Index: trunk/extensions/Validator/includes/ParameterCriterion.php |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | * |
9 | 9 | * @file ParameterCriterion.php |
10 | 10 | * @ingroup Validator |
| 11 | + * @ingroup Criteria |
11 | 12 | * |
12 | 13 | * @author Jeroen De Dauw |
13 | 14 | */ |
— | — | @@ -17,7 +18,7 @@ |
18 | 19 | /** |
19 | 20 | * Validate a value against the criterion. |
20 | 21 | * |
21 | | - * @param string $value |
| 22 | + * @param mixed $value |
22 | 23 | * |
23 | 24 | * @since 0.4 |
24 | 25 | * |
Index: trunk/extensions/Validator/includes/Parameter.php |
— | — | @@ -273,7 +273,11 @@ |
274 | 274 | } |
275 | 275 | |
276 | 276 | protected function validateCriteria( $value ) { |
277 | | - |
| 277 | + foreach ( $this->getCriteria() as $criterion ) { |
| 278 | + if ( !$criterion->validate( $value ) ) { |
| 279 | + |
| 280 | + } |
| 281 | + } |
278 | 282 | } |
279 | 283 | |
280 | 284 | /** |
— | — | @@ -310,22 +314,6 @@ |
311 | 315 | } |
312 | 316 | |
313 | 317 | /** |
314 | | - * Returns the list delimeter. |
315 | | - * |
316 | | - * @since 0.4 |
317 | | - * |
318 | | - * @return string |
319 | | - */ |
320 | | - public function getListDelimeter() { |
321 | | - if ( $this->isList() ) { |
322 | | - return count( $this->type ) > 1 ? $this->type[1] : self::$defaultListDelimeter; |
323 | | - } |
324 | | - else { |
325 | | - return false; |
326 | | - } |
327 | | - } |
328 | | - |
329 | | - /** |
330 | 318 | * Returns the parameter criteria. |
331 | 319 | * |
332 | 320 | * @since 0.4 |
Index: trunk/extensions/Validator/Validator.php |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | die( 'Not an entry point.' ); |
26 | 26 | } |
27 | 27 | |
28 | | -define( 'Validator_VERSION', '0.4 alpha-3' ); |
| 28 | +define( 'Validator_VERSION', '0.4 alpha-4' ); |
29 | 29 | |
30 | 30 | // Constants indicating the strictness of the parameter validation. |
31 | 31 | define( 'Validator_ERRORS_NONE', 0 ); |
— | — | @@ -54,7 +54,9 @@ |
55 | 55 | // Autoload the classes. |
56 | 56 | $incDir = dirname( __FILE__ ) . '/includes/'; |
57 | 57 | $wgAutoloadClasses['ListParameter'] = $incDir . 'ListParameter.php'; |
| 58 | +$wgAutoloadClasses['ListParameterCriterion']= $incDir . 'ListParameterCriterion.php'; |
58 | 59 | $wgAutoloadClasses['Parameter'] = $incDir . 'Parameter.php'; |
| 60 | +$wgAutoloadClasses['ParameterCriterion'] = $incDir . 'ParameterCriterion.php'; |
59 | 61 | $wgAutoloadClasses['ParserHook'] = $incDir . 'ParserHook.php'; |
60 | 62 | $wgAutoloadClasses['Validator'] = $incDir . 'Validator.php'; |
61 | 63 | $wgAutoloadClasses['TopologicalSort'] = $incDir . 'TopologicalSort.php'; |
— | — | @@ -70,8 +72,10 @@ |
71 | 73 | $wgAutoloadClasses['CriterionIsFloat'] = $incDir . 'criteria/CriterionIsFloat.php'; |
72 | 74 | $wgAutoloadClasses['CriterionIsInteger'] = $incDir . 'criteria/CriterionIsInteger.php'; |
73 | 75 | $wgAutoloadClasses['CriterionIsNumeric'] = $incDir . 'criteria/CriterionIsNumeric.php'; |
| 76 | +$wgAutoloadClasses['CriterionItemCount'] = $incDir . 'criteria/CriterionItemCount.php'; |
74 | 77 | $wgAutoloadClasses['CriterionMatchesRegex'] = $incDir . 'criteria/CriterionMatchesRegex.php'; |
75 | 78 | $wgAutoloadClasses['CriterionNotEmpty'] = $incDir . 'criteria/CriterionNotEmpty.php'; |
| 79 | +$wgAutoloadClasses['CriterionUniqueItems'] = $incDir . 'criteria/CriterionUniqueItems.php'; |
76 | 80 | |
77 | 81 | $wgAutoloadClasses['ValidatorListErrors'] = $incDir . 'parserHooks/Validator_ListErrors.php'; |
78 | 82 | unset( $incDir ); |