MediaWiki REL1_34
Wikimedia\ParamValidator\TypeDef Class Reference

Base definition for ParamValidator types. More...

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

Public Member Functions

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

Protected Attributes

Callbacks $callbacks
 

Detailed Description

Base definition for ParamValidator types.

All methods in this class accept an "options array". This is just the $options passed to ParamValidator::getValue(), ParamValidator::validateValue(), and the like and is intended for communication of non-global state.

Since
1.34 @unstable

Definition at line 15 of file TypeDef.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\ParamValidator\TypeDef::__construct ( Callbacks  $callbacks)

Definition at line 20 of file TypeDef.php.

Member Function Documentation

◆ describeSettings()

Wikimedia\ParamValidator\TypeDef::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 in Wikimedia\ParamValidator\TypeDef\IntegerDef, and Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef.

Definition at line 134 of file TypeDef.php.

References Wikimedia\ParamValidator\ParamValidator\PARAM_DEFAULT, and Wikimedia\ParamValidator\TypeDef\stringifyValue().

◆ getEnumValues()

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

Get the values for enum-like parameters.

This is primarily intended for documentation and implementation of PARAM_ALL; it is the responsibility of the TypeDef to ensure that validate() accepts the values returned here.

Parameters
string$nameParameter name being validated.
array$settingsParameter settings array.
array$optionsOptions array.
Returns
array|null All possible enumerated values, or null if this is not an enumeration.

Reimplemented in Wikimedia\ParamValidator\TypeDef\EnumDef.

Definition at line 85 of file TypeDef.php.

◆ getValue()

Wikimedia\ParamValidator\TypeDef::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 in Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef, and Wikimedia\ParamValidator\TypeDef\UploadDef.

Definition at line 39 of file TypeDef.php.

◆ normalizeSettings()

Wikimedia\ParamValidator\TypeDef::normalizeSettings ( array  $settings)

Normalize a settings array.

Parameters
array$settings
Returns
array

Reimplemented in Wikimedia\ParamValidator\TypeDef\IntegerDef, Wikimedia\ParamValidator\TypeDef\LimitDef, and Wikimedia\ParamValidator\TypeDef\PasswordDef.

Definition at line 68 of file TypeDef.php.

◆ stringifyValue()

Wikimedia\ParamValidator\TypeDef::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 in Wikimedia\ParamValidator\TypeDef\BooleanDef, Wikimedia\ParamValidator\TypeDef\EnumDef, Wikimedia\ParamValidator\TypeDef\FloatDef, Wikimedia\ParamValidator\TypeDef\TimestampDef, and Wikimedia\ParamValidator\TypeDef\UploadDef.

Definition at line 104 of file TypeDef.php.

Referenced by Wikimedia\ParamValidator\TypeDef\describeSettings().

◆ validate()

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

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 in Wikimedia\ParamValidator\TypeDef\BooleanDef, Wikimedia\ParamValidator\TypeDef\EnumDef, Wikimedia\ParamValidator\TypeDef\FloatDef, Wikimedia\ParamValidator\TypeDef\IntegerDef, Wikimedia\ParamValidator\TypeDef\LimitDef, Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef, Wikimedia\ParamValidator\TypeDef\StringDef, Wikimedia\ParamValidator\TypeDef\TimestampDef, and Wikimedia\ParamValidator\TypeDef\UploadDef.

Member Data Documentation

◆ $callbacks

Callbacks Wikimedia\ParamValidator\TypeDef::$callbacks
protected

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