Index: trunk/extensions/Validator/Validator.class.php |
— | — | @@ -69,7 +69,7 @@ |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * @var array Holder for the formatting functions. |
73 | | - */ |
| 73 | + */ |
74 | 74 | private static $outputFormats = array( |
75 | 75 | 'array' => array( 'ValidatorFormats', 'format_array' ), |
76 | 76 | 'list' => array( 'ValidatorFormats', 'format_list' ), |
— | — | @@ -77,6 +77,7 @@ |
78 | 78 | 'boolstr' => array( 'ValidatorFormats', 'format_boolean_string' ), |
79 | 79 | 'string' => array( 'ValidatorFormats', 'format_string' ), |
80 | 80 | 'unique_items' => array( 'ValidatorFormats', 'format_unique_items' ), |
| 81 | + 'filtered_array' => array( 'ValidatorFormats', 'format_filtered_array' ), |
81 | 82 | ); |
82 | 83 | |
83 | 84 | private $parameterInfo; |
Index: trunk/extensions/Validator/Validator_Formats.php |
— | — | @@ -31,6 +31,23 @@ |
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
| 35 | + * Ensures the value is an array. |
| 36 | + * |
| 37 | + * @param $value |
| 38 | + */ |
| 39 | + public static function format_filtered_array( &$value ) { |
| 40 | + // TODO: It's possible the way the allowed values are passed here is quite inneficient... |
| 41 | + $params = func_get_args(); |
| 42 | + array_shift( $params ); // Ommit the value |
| 43 | + |
| 44 | + self::format_array($value); |
| 45 | + $filtered = array(); |
| 46 | + foreach($value as $item) if (in_array($item, $params)) $filtered[] = $item; |
| 47 | + |
| 48 | + return $filtered; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
35 | 52 | * Changes the value to list notation, by separating items with a delimiter, |
36 | 53 | * and/or adding wrappers before and after the items. Intended for lists, but |
37 | 54 | * will also work for single values. |
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.2.1' ); |
| 28 | +define( 'Validator_VERSION', '0.2.2 a1' ); |
29 | 29 | |
30 | 30 | // Constants indicating the strictness of the parameter validation. |
31 | 31 | define( 'Validator_ERRORS_NONE', 0 ); |