MediaWiki  1.34.0
Wikimedia\ParamValidator\TypeDef\BooleanDef Class Reference

Type definition for boolean types. More...

Inheritance diagram for Wikimedia\ParamValidator\TypeDef\BooleanDef:
Collaboration diagram for Wikimedia\ParamValidator\TypeDef\BooleanDef:

Public Member Functions

 stringifyValue ( $name, $value, array $settings, array $options)
 Convert a value to a string representation. More...
 
 validate ( $name, $value, array $settings, array $options)
 Validate the value. More...
 
- Public Member Functions inherited from Wikimedia\ParamValidator\TypeDef
 __construct (Callbacks $callbacks)
 
 describeSettings ( $name, array $settings, array $options)
 "Describe" a settings array More...
 
 getEnumValues ( $name, array $settings, array $options)
 Get the values for enum-like parameters. More...
 
 getValue ( $name, array $settings, array $options)
 Get the value from the request. More...
 
 normalizeSettings (array $settings)
 Normalize a settings array. More...
 

Static Public Attributes

static $FALSEVALS = [ 'false', 'f', 'no', 'n', 'off', '0' ]
 
static $TRUEVALS = [ 'true', 't', 'yes', 'y', 'on', '1' ]
 

Additional Inherited Members

- Protected Attributes inherited from Wikimedia\ParamValidator\TypeDef
Callbacks $callbacks
 

Detailed Description

Type definition for boolean types.

This type accepts certain defined strings to mean 'true' or 'false'. The result from validate() is a PHP boolean.

ValidationException codes:

  • 'badbool': The value is not a recognized boolean. Data:
    • 'truevals': List of recognized values for "true".
    • 'falsevals': List of recognized values for "false".
Since
1.34 @unstable

Definition at line 22 of file BooleanDef.php.

Member Function Documentation

◆ stringifyValue()

Wikimedia\ParamValidator\TypeDef\BooleanDef::stringifyValue (   $name,
  $value,
array  $settings,
array  $options 
)

Convert a value to a string representation.

This is intended as the inverse of getValue() and validate(): this should accept anything returned by those methods or expected to be used as PARAM_DEFAULT, and if the string from this method is passed in as client input or PARAM_DEFAULT it should give equivalent output from validate().

Parameters
string$nameParameter name being converted.
mixed$valueParameter value being converted. Do not pass null.
array$settingsParameter settings array.
array$optionsOptions array.
Returns
string|null Return null if there is no representation of $value reasonably satisfying the description given.

Reimplemented from Wikimedia\ParamValidator\TypeDef.

Definition at line 42 of file BooleanDef.php.

◆ validate()

Wikimedia\ParamValidator\TypeDef\BooleanDef::validate (   $name,
  $value,
array  $settings,
array  $options 
)

Validate the value.

When ParamValidator is processing a multi-valued parameter, this will be called once for each of the supplied values. Which may mean zero calls.

When getValue() returned null, this will not be called.

Parameters
string$nameParameter name being validated.
mixed$valueValue to validate, from getValue().
array$settingsParameter settings array.
array$optionsOptions array. Note the following values that may be set by ParamValidator:
  • values-list: (string[]) If defined, values of a multi-valued parameter are being processed (and this array holds the full set of values).
Returns
mixed Validated value
Exceptions
ValidationExceptionif the value is invalid

Reimplemented from Wikimedia\ParamValidator\TypeDef.

Definition at line 27 of file BooleanDef.php.

Member Data Documentation

◆ $FALSEVALS

Wikimedia\ParamValidator\TypeDef\BooleanDef::$FALSEVALS = [ 'false', 'f', 'no', 'n', 'off', '0' ]
static

Definition at line 25 of file BooleanDef.php.

◆ $TRUEVALS

Wikimedia\ParamValidator\TypeDef\BooleanDef::$TRUEVALS = [ 'true', 't', 'yes', 'y', 'on', '1' ]
static

Definition at line 24 of file BooleanDef.php.


The documentation for this class was generated from the following file: