MediaWiki  1.34.0
Wikimedia\ParamValidator\TypeDef\EnumDef Class Reference

Type definition for enumeration types. More...

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

Public Member Functions

 getEnumValues ( $name, array $settings, array $options)
 Get the values for enum-like parameters. More...
 
 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...
 
 getValue ( $name, array $settings, array $options)
 Get the value from the request. More...
 
 normalizeSettings (array $settings)
 Normalize a settings array. More...
 

Public Attributes

const PARAM_DEPRECATED_VALUES = 'param-deprecated-values'
 (array) Associative array of deprecated values. More...
 

Additional Inherited Members

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

Detailed Description

Type definition for enumeration types.

This class expects that PARAM_TYPE is an array of allowed values. Subclasses may override getEnumValues() to determine the allowed values differently.

The result from validate() is one of the defined values.

ValidationException codes:

  • 'badvalue': The value is not a recognized value. No data.
  • 'notmulti': PARAM_ISMULTI is not set and the unrecognized value seems to be an attempt at using multiple values. No data.

Additional codes may be generated when using certain PARAM constants. See the constants' documentation for details.

Since
1.34 @unstable

Definition at line 28 of file EnumDef.php.

Member Function Documentation

◆ getEnumValues()

Wikimedia\ParamValidator\TypeDef\EnumDef::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 from Wikimedia\ParamValidator\TypeDef.

Definition at line 72 of file EnumDef.php.

References Wikimedia\ParamValidator\ParamValidator\PARAM_TYPE.

Referenced by Wikimedia\ParamValidator\TypeDef\EnumDef\validate().

◆ stringifyValue()

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

◆ validate()

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

References Wikimedia\ParamValidator\ParamValidator\explodeMultiValue(), and Wikimedia\ParamValidator\TypeDef\EnumDef\getEnumValues().

Member Data Documentation

◆ PARAM_DEPRECATED_VALUES

const Wikimedia\ParamValidator\TypeDef\EnumDef::PARAM_DEPRECATED_VALUES = 'param-deprecated-values'

(array) Associative array of deprecated values.

Keys are the deprecated parameter values, values are included in the ValidationException. If value is null, the parameter is considered not actually deprecated.

Note that this does not add any values to the enumeration, it only documents existing values as being deprecated.

ValidationException codes: (non-fatal)

  • 'deprecated-value': A deprecated value was encountered. Data:
    • 'flag': The value from the associative array.

Definition at line 44 of file EnumDef.php.


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