MediaWiki REL1_34
BooleanDef.php
Go to the documentation of this file.
1<?php
2
4
7
22class BooleanDef extends TypeDef {
23
24 public static $TRUEVALS = [ 'true', 't', 'yes', 'y', 'on', '1' ];
25 public static $FALSEVALS = [ 'false', 'f', 'no', 'n', 'off', '0' ];
26
27 public function validate( $name, $value, array $settings, array $options ) {
28 $value = strtolower( $value );
29 if ( in_array( $value, self::$TRUEVALS, true ) ) {
30 return true;
31 }
32 if ( $value === '' || in_array( $value, self::$FALSEVALS, true ) ) {
33 return false;
34 }
35
36 throw new ValidationException( $name, $value, $settings, 'badbool', [
37 'truevals' => self::$TRUEVALS,
38 'falsevals' => array_merge( self::$FALSEVALS, [ 'the empty string' ] ),
39 ] );
40 }
41
42 public function stringifyValue( $name, $value, array $settings, array $options ) {
43 return $value ? self::$TRUEVALS[0] : self::$FALSEVALS[0];
44 }
45
46}
Type definition for boolean types.
validate( $name, $value, array $settings, array $options)
Validate the value.
stringifyValue( $name, $value, array $settings, array $options)
Convert a value to a string representation.
Base definition for ParamValidator types.
Definition TypeDef.php:15