MediaWiki  1.34.0
Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef Class Reference

Type definition for checkbox-like boolean types. More...

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

Public Member Functions

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

Additional Inherited Members

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

Detailed Description

Type definition for checkbox-like boolean types.

This boolean is considered true if the parameter is present in the request, regardless of value. The only way for it to be false is for the parameter to be omitted entirely.

The result from validate() is a PHP boolean.

Since
1.34 @unstable

Definition at line 19 of file PresenceBooleanDef.php.

Member Function Documentation

◆ describeSettings()

Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef::describeSettings (   $name,
array  $settings,
array  $options 
)

"Describe" a settings array

This is intended to format data about a settings array using this type in a way that would be useful for automatically generated documentation or a machine-readable interface specification.

Keys in the description array should follow the same guidelines as the code described for ValidationException.

By default, each value in the description array is a single string, integer, or array. When ‘$options['compact’]` is supplied, each value is instead an array of such and related values may be combined. For example, a non-compact description for an integer type might include ‘[ 'default’ => 0, 'min' => 0, 'max' => 5 ], while in compact mode it might instead report[ 'default' => [ 'value' => 0 ], 'minmax' => [ 'min' => 0, 'max' => 5 ] ]‘ to facilitate auto-generated documentation turning that 'minmax’ into "Value must be between 0 and 5" rather than disconnected statements "Value must be >= 0" and "Value must be <= 5".

Parameters
string$nameParameter name being described.
array$settingsParameter settings array.
array$optionsOptions array. Defined options for this base class are:
  • 'compact': (bool) Enable compact mode, as described above.
Returns
array

Reimplemented from Wikimedia\ParamValidator\TypeDef.

Definition at line 29 of file PresenceBooleanDef.php.

◆ getValue()

Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef::getValue (   $name,
array  $settings,
array  $options 
)

Get the value from the request.

Note
Only override this if you need to use something other than $this->callbacks->getValue() to fetch the value. Reformatting from a string should typically be done by self::validate().
Handling of ParamValidator::PARAM_DEFAULT should be left to ParamValidator, as should PARAM_REQUIRED and the like.
Parameters
string$nameParameter name being fetched.
array$settingsParameter settings array.
array$optionsOptions array.
Returns
null|mixed Return null if the value wasn't present, otherwise a value to be passed to self::validate().

Reimplemented from Wikimedia\ParamValidator\TypeDef.

Definition at line 21 of file PresenceBooleanDef.php.

◆ validate()

Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef::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 25 of file PresenceBooleanDef.php.


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