MediaWiki REL1_34
|
Base definition for ParamValidator types. More...
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 |
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.
Definition at line 15 of file TypeDef.php.
Wikimedia\ParamValidator\TypeDef::__construct | ( | Callbacks | $callbacks | ) |
Definition at line 20 of file TypeDef.php.
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".
string | $name | Parameter name being described. |
array | $settings | Parameter settings array. |
array | $options | Options array. Defined options for this base class are:
|
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().
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.
string | $name | Parameter name being validated. |
array | $settings | Parameter settings array. |
array | $options | Options array. |
Reimplemented in Wikimedia\ParamValidator\TypeDef\EnumDef.
Definition at line 85 of file TypeDef.php.
Wikimedia\ParamValidator\TypeDef::getValue | ( | $name, | |
array | $settings, | ||
array | $options | ||
) |
Get the value from the request.
string | $name | Parameter name being fetched. |
array | $settings | Parameter settings array. |
array | $options | Options array. |
Reimplemented in Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef, and Wikimedia\ParamValidator\TypeDef\UploadDef.
Definition at line 39 of file TypeDef.php.
Wikimedia\ParamValidator\TypeDef::normalizeSettings | ( | array | $settings | ) |
Normalize a settings array.
array | $settings |
Reimplemented in Wikimedia\ParamValidator\TypeDef\IntegerDef, Wikimedia\ParamValidator\TypeDef\LimitDef, and Wikimedia\ParamValidator\TypeDef\PasswordDef.
Definition at line 68 of file TypeDef.php.
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().
string | $name | Parameter name being converted. |
mixed | $value | Parameter value being converted. Do not pass null. |
array | $settings | Parameter settings array. |
array | $options | Options array. |
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().
|
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.
string | $name | Parameter name being validated. |
mixed | $value | Value to validate, from getValue(). |
array | $settings | Parameter settings array. |
array | $options | Options array. Note the following values that may be set by ParamValidator:
|
ValidationException | if 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.
|
protected |
Definition at line 18 of file TypeDef.php.
Referenced by Wikimedia\ParamValidator\TypeDef\StringDef\__construct(), and Wikimedia\ParamValidator\TypeDef\TimestampDef\__construct().