Index: trunk/extensions/Validator/includes/ParserHook.php |
— | — | @@ -74,10 +74,13 @@ |
75 | 75 | * @param array $args |
76 | 76 | * @param Parser $parser |
77 | 77 | * @param PPFrame $frame |
| 78 | + * |
| 79 | + * @return string |
78 | 80 | */ |
79 | 81 | public function renderTag( $input, array $args, Parser $parser, PPFrame $frame ) { |
80 | 82 | $defaultParam = array_shift( $this->getDefaultParameters() ); |
81 | 83 | |
| 84 | + // If there is a first default parameter, set the tag contents as it's value. |
82 | 85 | if ( !is_null( $defaultParam ) ) { |
83 | 86 | $args[$defaultParam] = $input; |
84 | 87 | } |
— | — | @@ -92,6 +95,8 @@ |
93 | 96 | * |
94 | 97 | * @param Parser $parser |
95 | 98 | * ... further arguments ... |
| 99 | + * |
| 100 | + * @return array |
96 | 101 | */ |
97 | 102 | public function renderFunction() { |
98 | 103 | $args = func_get_args(); |
— | — | @@ -113,47 +118,35 @@ |
114 | 119 | * @return string |
115 | 120 | */ |
116 | 121 | public function validateAndRender( array $arguments, $parsed ) { |
117 | | - $manager = new ValidationManager(); |
| 122 | + global $egValidatorErrorLevel; |
| 123 | + |
| 124 | + $validator = new Validator(); |
118 | 125 | |
119 | 126 | if ( $parsed ) { |
120 | | - $doRender = $manager->manageParsedParameters( |
121 | | - $arguments, |
122 | | - $this->getParameterInfo() |
123 | | - ); |
| 127 | + $validator->setParameters( $arguments, $this->getParameterInfo() ); |
124 | 128 | } |
125 | 129 | else { |
126 | | - $doRender = $manager->manageParameters( |
127 | | - $arguments, |
128 | | - $this->getParameterInfo(), |
129 | | - $this->getDefaultParameters() |
130 | | - ); |
| 130 | + $validator->parseAndSetParams( $arguments, $this->getParameterInfo(), $this->getDefaultParameters() ); |
131 | 131 | } |
132 | 132 | |
133 | | - if ( $doRender ) { |
134 | | - $output = $this->render( $manager->getParameters( false ) ); |
| 133 | + $validator->validateAndFormatParameters(); |
| 134 | + |
| 135 | + if ( $validator->hasErrors() && $egValidatorErrorLevel < Validator_ERRORS_STRICT ) { |
| 136 | + $validator->correctInvalidParams(); |
135 | 137 | } |
| 138 | + |
| 139 | + if ( $validator->hasFatalError() ) { |
| 140 | + // TODO |
| 141 | + $output = 'Demo: fatal error'; |
| 142 | + } |
136 | 143 | else { |
137 | | - $output = $this->handleErrors( $manager ); |
| 144 | + $output = $this->render( $validator->getValidParams( false ) ); |
138 | 145 | } |
139 | 146 | |
140 | 147 | return $output; |
141 | 148 | } |
142 | 149 | |
143 | 150 | /** |
144 | | - * Handles any errors that occured. Messages that should be added the the regular |
145 | | - * output are returned. |
146 | | - * |
147 | | - * @since 0.4 |
148 | | - * |
149 | | - * @param ValidatorManager $manager |
150 | | - * |
151 | | - * @return string |
152 | | - */ |
153 | | - protected function handleErrors( ValidatorManager $manager ) { |
154 | | - |
155 | | - } |
156 | | - |
157 | | - /** |
158 | 151 | * Returns an array containing the parameter info. |
159 | 152 | * Override in deriving classes to add parameter info. |
160 | 153 | * |
Index: trunk/extensions/Validator/includes/Validator.php |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | /** |
58 | 58 | * @var array Holder for the validation functions. |
59 | 59 | */ |
60 | | - private static $mValidationFunctions = array( |
| 60 | + protected static $mValidationFunctions = array( |
61 | 61 | 'in_array' => array( 'ValidationFunctions', 'in_array' ), |
62 | 62 | 'in_range' => array( 'ValidationFunctions', 'in_range' ), |
63 | 63 | 'is_numeric' => array( 'ValidationFunctions', 'is_numeric' ), |
— | — | @@ -118,13 +118,6 @@ |
119 | 119 | protected $mValidParams = array(); |
120 | 120 | protected $mInvalidParams = array(); |
121 | 121 | protected $mUnknownParams = array(); |
122 | | - |
123 | | - /** |
124 | | - * Holds all errors and their meta data. |
125 | | - * |
126 | | - * @var associative array |
127 | | - */ |
128 | | - protected $mErrors = array(); |
129 | 122 | |
130 | 123 | /** |
131 | 124 | * List of ValidatorError. |
— | — | @@ -156,6 +149,13 @@ |
157 | 150 | // TODO |
158 | 151 | } |
159 | 152 | |
| 153 | + /** |
| 154 | + * Registers an error. |
| 155 | + * |
| 156 | + * @param string $message |
| 157 | + * @param mixed $tags string or array |
| 158 | + * @param integer $severity |
| 159 | + */ |
160 | 160 | protected function registerError( $message, $tags = array(), $severity = ValidatorError::SEVERITY_NORMAL ) { |
161 | 161 | $error = new ValidatorError( |
162 | 162 | $message, |