Index: trunk/extensions/Validator/Validator.class.php |
— | — | @@ -37,14 +37,14 @@ |
38 | 38 | /** |
39 | 39 | * @var boolean Indicates whether parameters that are provided more then once |
40 | 40 | * should be accepted, and use the first provided value, or not, and generate an error. |
41 | | - */ |
| 41 | + */ |
42 | 42 | public static $acceptOverriding = false; |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @var boolean Indicates if errors in list items should cause the item to be omitted, |
46 | 46 | * versus having the whole list be set to it's default. |
47 | | - */ |
48 | | - public static $perItemValidation = true; |
| 47 | + */ |
| 48 | + public static $perItemValidation = true; |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @var array Holder for the validation functions. |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | 'in_array' => array( 'ValidatorFunctions', 'in_array' ), |
55 | 55 | 'in_range' => array( 'ValidatorFunctions', 'in_range' ), |
56 | 56 | 'is_numeric' => 'is_numeric', |
57 | | - 'is_integer' => array( 'ValidatorFunctions', 'is_integer' ), |
| 57 | + 'is_integer' => array( 'ValidatorFunctions', 'is_integer' ), |
58 | 58 | 'not_empty' => array( 'ValidatorFunctions', 'not_empty' ), |
59 | 59 | 'has_length' => array( 'ValidatorFunctions', 'has_length' ), |
60 | 60 | 'regex' => array( 'ValidatorFunctions', 'regex' ), |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | private $parameterInfo; |
85 | 85 | private $rawParameters = array(); |
86 | 86 | |
87 | | - private $parameters= array(); |
| 87 | + private $parameters = array(); |
88 | 88 | private $valid = array(); |
89 | 89 | private $invalid = array(); |
90 | 90 | private $unknown = array(); |
— | — | @@ -123,7 +123,7 @@ |
124 | 124 | if ( $mainName ) { |
125 | 125 | // Check for parameter overriding. In most cases, this has already largely been taken care off, |
126 | 126 | // in the form of later parameters overriding earlier ones. This is not true for different aliases though. |
127 | | - if (! array_key_exists($mainName, $this->parameters) || self::$acceptOverriding ) { |
| 127 | + if ( ! array_key_exists( $mainName, $this->parameters ) || self::$acceptOverriding ) { |
128 | 128 | $this->parameters[$mainName] = $paramValue; |
129 | 129 | } |
130 | 130 | else { |
— | — | @@ -132,7 +132,7 @@ |
133 | 133 | } |
134 | 134 | else { // If the parameter is not found in the list of allowed ones, add an item to the $this->errors array. |
135 | 135 | if ( self::$storeUnknownParameters ) $this->unknown[$paramName] = $paramValue; |
136 | | - $this->errors[] = array( 'type' => 'unknown', 'name' => $paramName); |
| 136 | + $this->errors[] = array( 'type' => 'unknown', 'name' => $paramName ); |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
— | — | @@ -147,7 +147,7 @@ |
148 | 148 | if ( $this->validateParameter( $paramName, $paramValue ) ) { |
149 | 149 | // If the validation succeeded, add the parameter to the list of valid ones. |
150 | 150 | $this->valid[$paramName] = $paramValue; |
151 | | - $this->setOutputTypes($this->valid[$paramName], $paramInfo); |
| 151 | + $this->setOutputTypes( $this->valid[$paramName], $paramInfo ); |
152 | 152 | } |
153 | 153 | else { |
154 | 154 | // If the validation failed, add the parameter to the list of invalid ones. |
— | — | @@ -161,8 +161,8 @@ |
162 | 162 | } |
163 | 163 | else { |
164 | 164 | // Set the default value (or default 'default value' if none is provided), and ensure the type is correct. |
165 | | - $this->valid[$paramName] = array_key_exists( 'default', $paramInfo ) ? $paramInfo['default'] : ''; |
166 | | - $this->setOutputTypes($this->valid[$paramName], $paramInfo); |
| 165 | + $this->valid[$paramName] = array_key_exists( 'default', $paramInfo ) ? $paramInfo['default'] : ''; |
| 166 | + $this->setOutputTypes( $this->valid[$paramName], $paramInfo ); |
167 | 167 | } |
168 | 168 | } |
169 | 169 | } |
— | — | @@ -205,57 +205,57 @@ |
206 | 206 | * @param string $name |
207 | 207 | * @param $value |
208 | 208 | */ |
209 | | - private function cleanParameter( $name, &$value ) { |
| 209 | + private function cleanParameter( $name, &$value ) { |
210 | 210 | // Ensure there is a criteria array. |
211 | | - if (! array_key_exists('criteria', $this->parameterInfo[$name] )) { |
| 211 | + if ( ! array_key_exists( 'criteria', $this->parameterInfo[$name] ) ) { |
212 | 212 | $this->parameterInfo[$name]['criteria'] = array(); |
213 | | - } |
| 213 | + } |
214 | 214 | |
215 | 215 | // Ensure the type is set in array form. |
216 | | - if (! array_key_exists('type', $this->parameterInfo[$name] )) { |
217 | | - $this->parameterInfo[$name]['type'] = array('string'); |
| 216 | + if ( ! array_key_exists( 'type', $this->parameterInfo[$name] ) ) { |
| 217 | + $this->parameterInfo[$name]['type'] = array( 'string' ); |
218 | 218 | } |
219 | | - elseif(! is_array($this->parameterInfo[$name]['type'])) { |
220 | | - $this->parameterInfo[$name]['type'] = array($this->parameterInfo[$name]['type']); |
| 219 | + elseif ( ! is_array( $this->parameterInfo[$name]['type'] ) ) { |
| 220 | + $this->parameterInfo[$name]['type'] = array( $this->parameterInfo[$name]['type'] ); |
221 | 221 | } |
222 | 222 | |
223 | 223 | if ( array_key_exists( 'type', $this->parameterInfo[$name] ) ) { |
224 | 224 | // Add type specific criteria. |
225 | | - switch(strtolower($this->parameterInfo[$name]['type'][0])) { |
| 225 | + switch( strtolower( $this->parameterInfo[$name]['type'][0] ) ) { |
226 | 226 | case 'integer': |
227 | | - $this->addTypeCriteria($name, 'is_integer'); |
| 227 | + $this->addTypeCriteria( $name, 'is_integer' ); |
228 | 228 | break; |
229 | 229 | case 'number': |
230 | | - $this->addTypeCriteria($name, 'is_numeric'); |
| 230 | + $this->addTypeCriteria( $name, 'is_numeric' ); |
231 | 231 | break; |
232 | 232 | case 'boolean': |
233 | 233 | // TODO: work with list of true and false values. |
234 | | - $this->addTypeCriteria($name, 'in_array', array('yes', 'no', 'on', 'off')); |
| 234 | + $this->addTypeCriteria( $name, 'in_array', array( 'yes', 'no', 'on', 'off' ) ); |
235 | 235 | break; |
236 | 236 | case 'char': |
237 | | - $this->addTypeCriteria($name, 'has_length', array(1, 1)); |
238 | | - break; |
| 237 | + $this->addTypeCriteria( $name, 'has_length', array( 1, 1 ) ); |
| 238 | + break; |
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
242 | | - if (count($this->parameterInfo[$name]['type']) > 1 && $this->parameterInfo[$name]['type'][1] == 'list') { |
| 242 | + if ( count( $this->parameterInfo[$name]['type'] ) > 1 && $this->parameterInfo[$name]['type'][1] == 'list' ) { |
243 | 243 | // Trimming and splitting of list values. |
244 | | - $delimiter = count($this->parameterInfo[$name]['type']) > 2 ? $this->parameterInfo[$name]['type'][2] : ','; |
245 | | - $value = preg_replace('/((\s)*' . $delimiter . '(\s)*)/', $delimiter, $value); |
246 | | - $value = explode($delimiter, $value); |
| 244 | + $delimiter = count( $this->parameterInfo[$name]['type'] ) > 2 ? $this->parameterInfo[$name]['type'][2] : ','; |
| 245 | + $value = preg_replace( '/((\s)*' . $delimiter . '(\s)*)/', $delimiter, $value ); |
| 246 | + $value = explode( $delimiter, $value ); |
247 | 247 | } |
248 | | - elseif (count($this->parameterInfo[$name]['type']) > 1 && $this->parameterInfo[$name]['type'][1] == 'array' && is_array($value)) { |
| 248 | + elseif ( count( $this->parameterInfo[$name]['type'] ) > 1 && $this->parameterInfo[$name]['type'][1] == 'array' && is_array( $value ) ) { |
249 | 249 | // Trimming of array values. |
250 | | - for($i = count($value); $i > 0; $i--) $value[$i] = trim ($value[$i]); |
| 250 | + for ( $i = count( $value ); $i > 0; $i-- ) $value[$i] = trim ( $value[$i] ); |
251 | 251 | } |
252 | 252 | else { |
253 | 253 | // Trimming of non-list values. |
254 | | - $value = trim ($value); |
| 254 | + $value = trim ( $value ); |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | | - private function addTypeCriteria($paramName, $criteriaName, $criteriaArgs = array()) { |
259 | | - $this->parameterInfo[$paramName]['criteria'] = array_merge(array($criteriaName => $criteriaArgs), $this->parameterInfo[$paramName]['criteria']); |
| 258 | + private function addTypeCriteria( $paramName, $criteriaName, $criteriaArgs = array() ) { |
| 259 | + $this->parameterInfo[$paramName]['criteria'] = array_merge( array( $criteriaName => $criteriaArgs ), $this->parameterInfo[$paramName]['criteria'] ); |
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
— | — | @@ -270,12 +270,12 @@ |
271 | 271 | $hasNoErrors = true; |
272 | 272 | $checkItemCriteria = true; |
273 | 273 | |
274 | | - if (array_key_exists('list-criteria', $this->parameterInfo[$name])) { |
| 274 | + if ( array_key_exists( 'list-criteria', $this->parameterInfo[$name] ) ) { |
275 | 275 | foreach ( $this->parameterInfo[$name]['list-criteria'] as $criteriaName => $criteriaArgs ) { |
276 | 276 | // Get the validation function. If there is no matching function, throw an exception. |
277 | | - if (array_key_exists($criteriaName, self::$listValidationFunctions)) { |
| 277 | + if ( array_key_exists( $criteriaName, self::$listValidationFunctions ) ) { |
278 | 278 | $validationFunction = self::$listValidationFunctions[$criteriaName]; |
279 | | - $isValid = $this->doCriteriaValidation($validationFunction, $value, $criteriaArgs); |
| 279 | + $isValid = $this->doCriteriaValidation( $validationFunction, $value, $criteriaArgs ); |
280 | 280 | |
281 | 281 | // Add a new error when the validation failed, and break the loop if errors for one parameter should not be accumulated. |
282 | 282 | if ( ! $isValid ) { |
— | — | @@ -287,16 +287,16 @@ |
288 | 288 | $checkItemCriteria = false; |
289 | 289 | break; |
290 | 290 | } |
291 | | - } |
| 291 | + } |
292 | 292 | } |
293 | 293 | else { |
294 | 294 | $hasNoErrors = false; |
295 | 295 | throw new Exception( 'There is no validation function for list criteria type ' . $criteriaName ); |
296 | | - } |
| 296 | + } |
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
300 | | - if ($checkItemCriteria) $hasNoErrors = $hasNoErrors && $this->doItemValidation($name, $value); |
| 300 | + if ( $checkItemCriteria ) $hasNoErrors = $hasNoErrors && $this->doItemValidation( $name, $value ); |
301 | 301 | |
302 | 302 | return $hasNoErrors; |
303 | 303 | } |
— | — | @@ -315,24 +315,24 @@ |
316 | 316 | // Go through all item criteria. |
317 | 317 | foreach ( $this->parameterInfo[$name]['criteria'] as $criteriaName => $criteriaArgs ) { |
318 | 318 | // Get the validation function. If there is no matching function, throw an exception. |
319 | | - if (array_key_exists($criteriaName, self::$validationFunctions)) { |
| 319 | + if ( array_key_exists( $criteriaName, self::$validationFunctions ) ) { |
320 | 320 | $validationFunction = self::$validationFunctions[$criteriaName]; |
321 | 321 | |
322 | | - if (is_array($value)) { |
| 322 | + if ( is_array( $value ) ) { |
323 | 323 | // Handling of list parameters |
324 | 324 | $invalidItems = array(); |
325 | 325 | $validItems = array(); |
326 | 326 | |
327 | 327 | // Loop through all the items in the parameter value, and validate them. |
328 | | - foreach($value as $item) { |
329 | | - $isValid = $this->doCriteriaValidation($validationFunction, $item, $criteriaArgs); |
330 | | - if ($isValid) { |
| 328 | + foreach ( $value as $item ) { |
| 329 | + $isValid = $this->doCriteriaValidation( $validationFunction, $item, $criteriaArgs ); |
| 330 | + if ( $isValid ) { |
331 | 331 | // If per item validation is on, store the valid items, so only these can be returned by Validator. |
332 | | - if (self::$perItemValidation) $validItems[] = $item; |
| 332 | + if ( self::$perItemValidation ) $validItems[] = $item; |
333 | 333 | } |
334 | 334 | else { |
335 | 335 | // If per item validation is on, store the invalid items, so a fitting error message can be created. |
336 | | - if (self::$perItemValidation) { |
| 336 | + if ( self::$perItemValidation ) { |
337 | 337 | $invalidItems[] = $item; |
338 | 338 | } |
339 | 339 | else { |
— | — | @@ -343,12 +343,12 @@ |
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | | - if (self::$perItemValidation) { |
| 347 | + if ( self::$perItemValidation ) { |
348 | 348 | // If per item validation is on, the parameter value is valid as long as there is at least one valid item. |
349 | | - $isValid = count($validItems) > 0; |
| 349 | + $isValid = count( $validItems ) > 0; |
350 | 350 | |
351 | 351 | // If the value is valid, but there are invalid items, add an error with a list of these items. |
352 | | - if ($isValid && count($invalidItems) > 0) { |
| 352 | + if ( $isValid && count( $invalidItems ) > 0 ) { |
353 | 353 | $value = $validItems; |
354 | 354 | $this->errors[] = array( 'type' => $criteriaName, 'args' => $criteriaArgs, 'name' => $name, 'list' => true, 'invalid-items' => $invalidItems ); |
355 | 355 | } |
— | — | @@ -356,23 +356,23 @@ |
357 | 357 | } |
358 | 358 | else { |
359 | 359 | // Determine if the value is valid for single valued parameters. |
360 | | - $isValid = $this->doCriteriaValidation($validationFunction, $value, $criteriaArgs); |
| 360 | + $isValid = $this->doCriteriaValidation( $validationFunction, $value, $criteriaArgs ); |
361 | 361 | } |
362 | 362 | |
363 | 363 | // Add a new error when the validation failed, and break the loop if errors for one parameter should not be accumulated. |
364 | 364 | if ( ! $isValid ) { |
365 | | - $isList = is_array($value); |
366 | | - if ($isList) $value = $this->rawParameters[$name]; |
| 365 | + $isList = is_array( $value ); |
| 366 | + if ( $isList ) $value = $this->rawParameters[$name]; |
367 | 367 | $this->errors[] = array( 'type' => $criteriaName, 'args' => $criteriaArgs, 'name' => $name, 'list' => $isList, 'value' => $value ); |
368 | 368 | $hasNoErrors = false; |
369 | 369 | if ( ! self::$accumulateParameterErrors ) break; |
370 | | - } |
| 370 | + } |
371 | 371 | } |
372 | 372 | else { |
373 | 373 | $hasNoErrors = false; |
374 | 374 | throw new Exception( 'There is no validation function for criteria type ' . $criteriaName ); |
375 | 375 | } |
376 | | - } |
| 376 | + } |
377 | 377 | |
378 | 378 | return $hasNoErrors; |
379 | 379 | } |
— | — | @@ -386,9 +386,9 @@ |
387 | 387 | * |
388 | 388 | * @return unknown_type |
389 | 389 | */ |
390 | | - private function doCriteriaValidation($validationFunction, $value, $criteriaArgs) { |
| 390 | + private function doCriteriaValidation( $validationFunction, $value, $criteriaArgs ) { |
391 | 391 | // Call the validation function and store the result. |
392 | | - return call_user_func_array( $validationFunction, array_merge(array($value), $criteriaArgs) ); |
| 392 | + return call_user_func_array( $validationFunction, array_merge( array( $value ), $criteriaArgs ) ); |
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
— | — | @@ -398,9 +398,9 @@ |
399 | 399 | foreach ( $this->invalid as $paramName => $paramValue ) { |
400 | 400 | unset( $this->invalid[$paramName] ); |
401 | 401 | $this->valid[$paramName] = array_key_exists( 'default', $this->parameterInfo[$paramName] ) ? $this->parameterInfo[$paramName]['default'] : ''; |
402 | | - $this->setOutputTypes($this->valid[$paramName], $this->parameterInfo[$paramName]); |
| 402 | + $this->setOutputTypes( $this->valid[$paramName], $this->parameterInfo[$paramName] ); |
403 | 403 | } |
404 | | - } |
| 404 | + } |
405 | 405 | |
406 | 406 | /** |
407 | 407 | * Ensures the output type values are arrays, and then calls setOutputType. |
— | — | @@ -409,16 +409,16 @@ |
410 | 410 | * @param $info |
411 | 411 | * @return unknown_type |
412 | 412 | */ |
413 | | - private function setOutputTypes(&$value, array $info) { |
414 | | - if (array_key_exists('output-types', $info)) { |
415 | | - for($i = 0, $c = count($info['output-types']); $i < $c; $i++) { |
416 | | - if (! is_array($info['output-types'][$i])) $info['output-types'][$i] = array($info['output-types'][$i]); |
417 | | - $this->setOutputType($value, $info['output-types'][$i]); |
| 413 | + private function setOutputTypes( &$value, array $info ) { |
| 414 | + if ( array_key_exists( 'output-types', $info ) ) { |
| 415 | + for ( $i = 0, $c = count( $info['output-types'] ); $i < $c; $i++ ) { |
| 416 | + if ( ! is_array( $info['output-types'][$i] ) ) $info['output-types'][$i] = array( $info['output-types'][$i] ); |
| 417 | + $this->setOutputType( $value, $info['output-types'][$i] ); |
418 | 418 | } |
419 | 419 | } |
420 | | - elseif (array_key_exists('output-type', $info)) { |
421 | | - if (! is_array($info['output-type'])) $info['output-type'] = array($info['output-type']); |
422 | | - $this->setOutputType($value, $info['output-type']); |
| 420 | + elseif ( array_key_exists( 'output-type', $info ) ) { |
| 421 | + if ( ! is_array( $info['output-type'] ) ) $info['output-type'] = array( $info['output-type'] ); |
| 422 | + $this->setOutputType( $value, $info['output-type'] ); |
423 | 423 | } |
424 | 424 | |
425 | 425 | } |
— | — | @@ -429,14 +429,14 @@ |
430 | 430 | * @param $value |
431 | 431 | * @param array $typeInfo |
432 | 432 | */ |
433 | | - private function setOutputType(&$value, array $typeInfo) { |
| 433 | + private function setOutputType( &$value, array $typeInfo ) { |
434 | 434 | // The output type is the first value in the type info array. |
435 | 435 | // The remaining ones will be any extra arguments. |
436 | | - $outputType = strtolower(array_shift($typeInfo)); |
| 436 | + $outputType = strtolower( array_shift( $typeInfo ) ); |
437 | 437 | |
438 | | - if (array_key_exists($outputType, self::$outputFormats)) { |
| 438 | + if ( array_key_exists( $outputType, self::$outputFormats ) ) { |
439 | 439 | // Call the formatting function with as first parameter the value, followed by the extra arguments. |
440 | | - call_user_func_array( self::$outputFormats[$outputType], array_merge(array(&$value), $typeInfo) ); |
| 440 | + call_user_func_array( self::$outputFormats[$outputType], array_merge( array( &$value ), $typeInfo ) ); |
441 | 441 | } |
442 | 442 | else { |
443 | 443 | throw new Exception( 'There is no formatting function for output format ' . $outputType ); |
— | — | @@ -492,7 +492,7 @@ |
493 | 493 | */ |
494 | 494 | public static function addListValidationFunction( $criteriaName, array $functionName ) { |
495 | 495 | self::$listValidationFunctions[$criteriaName] = $functionName; |
496 | | - } |
| 496 | + } |
497 | 497 | |
498 | 498 | /** |
499 | 499 | * Adds a new output format and the formatting function that should validate values of this type. |
— | — | @@ -504,5 +504,5 @@ |
505 | 505 | */ |
506 | 506 | public static function addOutputFormat( $formatName, array $functionName ) { |
507 | 507 | self::$outputFormats[$formatName] = $functionName; |
508 | | - } |
| 508 | + } |
509 | 509 | } |
\ No newline at end of file |
Index: trunk/extensions/Validator/Validator_Functions.php |
— | — | @@ -34,8 +34,8 @@ |
35 | 35 | public static function in_range( $value, $lower = false, $upper = false ) { |
36 | 36 | if ( ! is_numeric( $value ) ) return false; |
37 | 37 | $value = (int)$value; |
38 | | - if ($lower !== false && $value < $lower) return false; |
39 | | - if ($upper !== false && $value > $upper) return false; |
| 38 | + if ( $lower !== false && $value < $lower ) return false; |
| 39 | + if ( $upper !== false && $value > $upper ) return false; |
40 | 40 | return true; |
41 | 41 | } |
42 | 42 | |
— | — | @@ -61,8 +61,8 @@ |
62 | 62 | // TODO: It's possible the way the allowed values are passed here is quite inneficient... |
63 | 63 | $params = func_get_args(); |
64 | 64 | array_shift( $params ); // Ommit the value |
65 | | - return in_array($value, $params); |
66 | | - } |
| 65 | + return in_array( $value, $params ); |
| 66 | + } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Returns whether a variable is an integer or an integer string. Uses the native PHP function. |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | */ |
75 | 75 | public static function is_integer( $value ) { |
76 | 76 | return ctype_digit( (string)$value ); |
77 | | - } |
| 77 | + } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Returns whether the length of the value is within a certain range. Upper bound included. |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | * @return boolean |
87 | 87 | */ |
88 | 88 | public static function has_length( $value, $lower = false, $upper = false ) { |
89 | | - return self::in_range(strlen($value), $lower, $upper); |
| 89 | + return self::in_range( strlen( $value ), $lower, $upper ); |
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
— | — | @@ -98,7 +98,7 @@ |
99 | 99 | * @return boolean |
100 | 100 | */ |
101 | 101 | public static function has_item_count( array $values, $lower = false, $upper = false ) { |
102 | | - return self::in_range(count($values), $lower, $upper); |
| 102 | + return self::in_range( count( $values ), $lower, $upper ); |
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
— | — | @@ -109,8 +109,8 @@ |
110 | 110 | * @return boolean |
111 | 111 | */ |
112 | 112 | public static function has_unique_items( array $values ) { |
113 | | - return count($values) == count(array_unique($values)); |
114 | | - } |
| 113 | + return count( $values ) == count( array_unique( $values ) ); |
| 114 | + } |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * Returns the result of preg_match. |
— | — | @@ -121,6 +121,6 @@ |
122 | 122 | * @return boolean |
123 | 123 | */ |
124 | 124 | public static function regex( $value, $pattern ) { |
125 | | - return (bool)preg_match($pattern, $value); |
| 125 | + return (bool)preg_match( $pattern, $value ); |
126 | 126 | } |
127 | 127 | } |
Index: trunk/extensions/Validator/Validator_Manager.php |
— | — | @@ -67,21 +67,21 @@ |
68 | 68 | $errors = array(); |
69 | 69 | |
70 | 70 | foreach ( $this->errors as $error ) { |
71 | | - $error['name'] = '<b>' . Sanitizer::escapeId($error['name']) . '</b>'; |
| 71 | + $error['name'] = '<b>' . Sanitizer::escapeId( $error['name'] ) . '</b>'; |
72 | 72 | |
73 | | - if ($error['type'] == 'unknown') { |
| 73 | + if ( $error['type'] == 'unknown' ) { |
74 | 74 | $errors[] = wfMsgExt( 'validator_error_unknown_argument', array( 'parsemag' ), $error['name'] ); |
75 | 75 | } |
76 | | - elseif ($error['type'] == 'missing') { |
| 76 | + elseif ( $error['type'] == 'missing' ) { |
77 | 77 | $errors[] = wfMsgExt( 'validator_error_required_missing', array( 'parsemag' ), $error['name'] ); |
78 | 78 | } |
79 | | - elseif (array_key_exists('list', $error) && $error['list']) { |
| 79 | + elseif ( array_key_exists( 'list', $error ) && $error['list'] ) { |
80 | 80 | switch( $error['type'] ) { |
81 | 81 | case 'not_empty' : |
82 | 82 | $msg = wfMsgExt( 'validator_list_error_empty_argument', array( 'parsemag' ), $error['name'] ); |
83 | 83 | break; |
84 | 84 | case 'in_range' : |
85 | | - $msg = wfMsgExt( 'validator_list_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0]. '</b>', '<b>' .$error['args'][1]. '</b>' ); |
| 85 | + $msg = wfMsgExt( 'validator_list_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0] . '</b>', '<b>' . $error['args'][1] . '</b>' ); |
86 | 86 | break; |
87 | 87 | case 'is_numeric' : |
88 | 88 | $msg = wfMsgExt( 'validator_list_error_must_be_number', array( 'parsemag' ), $error['name'] ); |
— | — | @@ -89,7 +89,7 @@ |
90 | 90 | case 'is_integer' : |
91 | 91 | $msg = wfMsgExt( 'validator_list_error_must_be_integer', array( 'parsemag' ), $error['name'] ); |
92 | 92 | break; |
93 | | - case 'in_array' : |
| 93 | + case 'in_array' : |
94 | 94 | $itemsText = $wgLang->listToText( $error['args'] ); |
95 | 95 | $msg = wfMsgExt( 'validator_error_accepts_only', array( 'parsemag' ), $error['name'], $itemsText, count( $error['args'] ) ); |
96 | 96 | break; |
— | — | @@ -98,11 +98,11 @@ |
99 | 99 | break; |
100 | 100 | } |
101 | 101 | |
102 | | - if (array_key_exists('invalid-items', $error)) { |
| 102 | + if ( array_key_exists( 'invalid-items', $error ) ) { |
103 | 103 | $omitted = array(); |
104 | | - foreach($error['invalid-items'] as $item) $omitted[] = Sanitizer::escapeId($item); |
105 | | - $msg .= ' ' . wfMsgExt( 'validator_list_omitted', array( 'parsemag' ), |
106 | | - $wgLang->listToText($omitted), count($omitted) ); |
| 104 | + foreach ( $error['invalid-items'] as $item ) $omitted[] = Sanitizer::escapeId( $item ); |
| 105 | + $msg .= ' ' . wfMsgExt( 'validator_list_omitted', array( 'parsemag' ), |
| 106 | + $wgLang->listToText( $omitted ), count( $omitted ) ); |
107 | 107 | } |
108 | 108 | |
109 | 109 | $errors[] = $msg; |
— | — | @@ -113,7 +113,7 @@ |
114 | 114 | $errors[] = wfMsgExt( 'validator_error_empty_argument', array( 'parsemag' ), $error['name'] ); |
115 | 115 | break; |
116 | 116 | case 'in_range' : |
117 | | - $errors[] = wfMsgExt( 'validator_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0]. '</b>', '<b>' .$error['args'][1]. '</b>' ); |
| 117 | + $errors[] = wfMsgExt( 'validator_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0] . '</b>', '<b>' . $error['args'][1] . '</b>' ); |
118 | 118 | break; |
119 | 119 | case 'is_numeric' : |
120 | 120 | $errors[] = wfMsgExt( 'validator_error_must_be_number', array( 'parsemag' ), $error['name'] ); |
— | — | @@ -121,14 +121,14 @@ |
122 | 122 | case 'is_integer' : |
123 | 123 | $errors[] = wfMsgExt( 'validator_error_must_be_integer', array( 'parsemag' ), $error['name'] ); |
124 | 124 | break; |
125 | | - case 'in_array' : |
| 125 | + case 'in_array' : |
126 | 126 | $itemsText = $wgLang->listToText( $error['args'] ); |
127 | 127 | $errors[] = wfMsgExt( 'validator_error_accepts_only', array( 'parsemag' ), $error['name'], $itemsText, count( $error['args'] ) ); |
128 | 128 | break; |
129 | 129 | case 'invalid' : default : |
130 | 130 | $errors[] = wfMsgExt( 'validator_error_invalid_argument', array( 'parsemag' ), '<b>' . Sanitizer::escapeId( $error['value'] ) . '</b>', $error['name'] ); |
131 | 131 | break; |
132 | | - } |
| 132 | + } |
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
Index: trunk/extensions/Validator/Validator_Formats.php |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | * @param $value |
29 | 29 | */ |
30 | 30 | public static function format_array( &$value ) { |
31 | | - if (! is_array($value)) $value = array($value); |
| 31 | + if ( ! is_array( $value ) ) $value = array( $value ); |
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
— | — | @@ -39,13 +39,13 @@ |
40 | 40 | // TODO: It's possible the way the allowed values are passed here is quite inneficient... |
41 | 41 | $params = func_get_args(); |
42 | 42 | array_shift( $params ); // Ommit the value |
43 | | - |
44 | | - self::format_array($value); |
| 43 | + |
| 44 | + self::format_array( $value ); |
45 | 45 | $filtered = array(); |
46 | | - foreach($value as $item) if (in_array($item, $params)) $filtered[] = $item; |
| 46 | + foreach ( $value as $item ) if ( in_array( $item, $params ) ) $filtered[] = $item; |
47 | 47 | |
48 | 48 | return $filtered; |
49 | | - } |
| 49 | + } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Changes the value to list notation, by separating items with a delimiter, |
— | — | @@ -57,8 +57,8 @@ |
58 | 58 | * @param $wrapper |
59 | 59 | */ |
60 | 60 | public static function format_list( &$value, $delimiter = ',', $wrapper = '' ) { |
61 | | - self::format_array($value); |
62 | | - $value = $wrapper . implode($wrapper . $delimiter . $wrapper, $value) . $wrapper; |
| 61 | + self::format_array( $value ); |
| 62 | + $value = $wrapper . implode( $wrapper . $delimiter . $wrapper, $value ) . $wrapper; |
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
— | — | @@ -69,13 +69,13 @@ |
70 | 70 | * @param $value |
71 | 71 | */ |
72 | 72 | public static function format_boolean( &$value ) { |
73 | | - if (is_array($value)) { |
| 73 | + if ( is_array( $value ) ) { |
74 | 74 | $boolArray = array(); |
75 | | - foreach ($value as $item) $boolArray[] = in_array($item, array('yes', 'on')); |
| 75 | + foreach ( $value as $item ) $boolArray[] = in_array( $item, array( 'yes', 'on' ) ); |
76 | 76 | $value = $boolArray; |
77 | 77 | } |
78 | 78 | else { |
79 | | - $value = in_array($value, array('yes', 'on')); |
| 79 | + $value = in_array( $value, array( 'yes', 'on' ) ); |
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
— | — | @@ -85,16 +85,16 @@ |
86 | 86 | * @param $value |
87 | 87 | */ |
88 | 88 | public static function format_boolean_string( &$value ) { |
89 | | - self::format_boolean($value); |
90 | | - if (is_array($value)) { |
| 89 | + self::format_boolean( $value ); |
| 90 | + if ( is_array( $value ) ) { |
91 | 91 | $boolArray = array(); |
92 | | - foreach ($value as $item) $boolArray[] = $item ? 'true' : 'false'; |
| 92 | + foreach ( $value as $item ) $boolArray[] = $item ? 'true' : 'false'; |
93 | 93 | $value = $boolArray; |
94 | 94 | } |
95 | 95 | else { |
96 | 96 | $value = $value ? 'true' : 'false'; |
97 | 97 | } |
98 | | - } |
| 98 | + } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Changes lists into strings, by enumerating the items using $wgLang->listToText. |
— | — | @@ -102,10 +102,10 @@ |
103 | 103 | * @param $value |
104 | 104 | */ |
105 | 105 | public static function format_string( &$value ) { |
106 | | - if (is_array($value)) { |
| 106 | + if ( is_array( $value ) ) { |
107 | 107 | global $wgLang; |
108 | | - $value = $wgLang->listToText($value); |
109 | | - } |
| 108 | + $value = $wgLang->listToText( $value ); |
| 109 | + } |
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | * @param $value |
116 | 116 | */ |
117 | 117 | public static function format_unique_items( &$value ) { |
118 | | - if (is_array($value)) $value = array_unique($value); |
| 118 | + if ( is_array( $value ) ) $value = array_unique( $value ); |
119 | 119 | } |
120 | 120 | |
121 | 121 | } |
\ No newline at end of file |
Index: trunk/extensions/Validator/Validator.i18n.php |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | 'validator_list_error_must_be_number' => 'Parameter $1 can only contain numbers.', |
39 | 39 | 'validator_list_error_must_be_integer' => 'Parameter $1 can only contain integers.', |
40 | 40 | 'validator_list_error_invalid_range' => 'All values of parameter $1 must be between $2 and $3.', |
41 | | - 'validator_list_error_invalid_argument' => 'One or more values for parameter $1 are invalid.', |
| 41 | + 'validator_list_error_invalid_argument' => 'One or more values for parameter $1 are invalid.', |
42 | 42 | |
43 | 43 | 'validator_list_omitted' => 'The {{PLURAL:$2|value|values}} $1 {{PLURAL:$2|has|have}} been omitted.', |
44 | 44 | |