Index: trunk/extensions/Validator/includes/manipulations/ParamManipualtionBoolean.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Parameter manipulation converting the value to a boolean. |
| 6 | + * |
| 7 | + * @since 0.4 |
| 8 | + * |
| 9 | + * @file ParamManipulationBoolean.php |
| 10 | + * @ingroup Validator |
| 11 | + * @ingroup ParameterManipulations |
| 12 | + * |
| 13 | + * @author Jeroen De Dauw |
| 14 | + */ |
| 15 | +class ParamManipulationBoolean extends ItemParameterManipulation { |
| 16 | + |
| 17 | + /** |
| 18 | + * Constructor. |
| 19 | + * |
| 20 | + * @since 0.4 |
| 21 | + */ |
| 22 | + public function __construct() { |
| 23 | + parent::__construct(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @see ItemParameterManipulation::doManipulation |
| 28 | + * |
| 29 | + * @since 0.4 |
| 30 | + */ |
| 31 | + public function doManipulation( &$value, array &$parameters ) { |
| 32 | + $value = in_array( $value, array( 'yes', 'on' ) ); |
| 33 | + } |
| 34 | + |
| 35 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Validator/includes/manipulations/ParamManipualtionBoolean.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 36 | + native |
Index: trunk/extensions/Validator/includes/ItemParameterManipualtion.php |
— | — | @@ -16,6 +16,18 @@ |
17 | 17 | abstract class ItemParameterManipulation extends ParameterManipulation { |
18 | 18 | |
19 | 19 | /** |
| 20 | + * Manipulate an actual value. |
| 21 | + * |
| 22 | + * @param string $value |
| 23 | + * @param array $parameters |
| 24 | + * |
| 25 | + * @since 0.4 |
| 26 | + * |
| 27 | + * @return mixed |
| 28 | + */ |
| 29 | + protected abstract function doManipulation( &$value, array &$parameters ); |
| 30 | + |
| 31 | + /** |
20 | 32 | * Constructor. |
21 | 33 | * |
22 | 34 | * @since 0.4 |
— | — | @@ -30,5 +42,23 @@ |
31 | 43 | public function isForLists() { |
32 | 44 | return false; |
33 | 45 | } |
| 46 | + /** |
| 47 | + * Validate a parameter against the criterion. |
| 48 | + * |
| 49 | + * @param Parameter $parameter |
| 50 | + * @param array $parameters |
| 51 | + * |
| 52 | + * @since 0.4 |
| 53 | + */ |
| 54 | + public abstract function manipulate( Parameter &$parameter, array &$parameters ) { |
| 55 | + if ( is_array( $parameter->value ) ) { |
| 56 | + foreach ( $parameter->value as &$item ) { |
| 57 | + $this->doManipulation( $item, $parameters ); |
| 58 | + } |
| 59 | + } |
| 60 | + else { |
| 61 | + $this->doManipulation( $parameter->value, $parameters ); |
| 62 | + } |
| 63 | + } |
34 | 64 | |
35 | 65 | } |
\ No newline at end of file |