MediaWiki  1.34.0
Wikimedia\ParamValidator\TypeDef\IntegerDef Class Reference

Type definition for integer types. More...

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

Public Member Functions

 describeSettings ( $name, array $settings, array $options)
 "Describe" a settings array More...
 
 normalizeSettings (array $settings)
 Normalize a settings array. 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...
 
 getValue ( $name, array $settings, array $options)
 Get the value from the request. More...
 
 stringifyValue ( $name, $value, array $settings, array $options)
 Convert a value to a string representation. More...
 

Public Attributes

const PARAM_IGNORE_RANGE = 'param-ignore-range'
 (bool) Whether to enforce the specified range. More...
 
const PARAM_MAX = 'param-max'
 (int) Maximum allowed value (normal limits) More...
 
const PARAM_MAX2 = 'param-max2'
 (int) Maximum allowed value (high limits) More...
 
const PARAM_MIN = 'param-min'
 (int) Minimum allowed value. More...
 

Additional Inherited Members

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

Detailed Description

Type definition for integer types.

A valid representation consists of an optional sign (+ or -) followed by one or more decimal digits.

The result from validate() is a PHP integer.

  • ValidationException codes:
    • 'badinteger': The value was invalid or could not be represented as a PHP integer. 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 26 of file IntegerDef.php.

Member Function Documentation

◆ describeSettings()

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

References Wikimedia\ParamValidator\TypeDef\IntegerDef\PARAM_MAX, Wikimedia\ParamValidator\TypeDef\IntegerDef\PARAM_MAX2, and Wikimedia\ParamValidator\TypeDef\IntegerDef\PARAM_MIN.

◆ normalizeSettings()

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

Normalize a settings array.

Parameters
array$settings
Returns
array

Reimplemented from Wikimedia\ParamValidator\TypeDef.

Reimplemented in Wikimedia\ParamValidator\TypeDef\LimitDef.

Definition at line 120 of file IntegerDef.php.

References Wikimedia\ParamValidator\TypeDef\IntegerDef\PARAM_MAX, and Wikimedia\ParamValidator\TypeDef\IntegerDef\PARAM_MAX2.

◆ validate()

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

Reimplemented in Wikimedia\ParamValidator\TypeDef\LimitDef.

Definition at line 72 of file IntegerDef.php.

References Wikimedia\ParamValidator\TypeDef\IntegerDef\PARAM_MAX, Wikimedia\ParamValidator\TypeDef\IntegerDef\PARAM_MAX2, and Wikimedia\ParamValidator\TypeDef\IntegerDef\PARAM_MIN.

Member Data Documentation

◆ PARAM_IGNORE_RANGE

const Wikimedia\ParamValidator\TypeDef\IntegerDef::PARAM_IGNORE_RANGE = 'param-ignore-range'

(bool) Whether to enforce the specified range.

If set and truthy, ValidationExceptions from PARAM_MIN, PARAM_MAX, and PARAM_MAX2 are non-fatal.

Definition at line 34 of file IntegerDef.php.

◆ PARAM_MAX

const Wikimedia\ParamValidator\TypeDef\IntegerDef::PARAM_MAX = 'param-max'

(int) Maximum allowed value (normal limits)

ValidationException codes:

  • 'abovemaximum': The value was above the allowed maximum. Data:
    • 'min': Allowed minimum, or empty string if there is none.
    • 'max': Allowed (normal) maximum, or empty string if there is none.
    • 'max2': Allowed (high limits) maximum, or empty string if there is none.

Definition at line 56 of file IntegerDef.php.

Referenced by Wikimedia\ParamValidator\TypeDef\IntegerDef\describeSettings(), Wikimedia\ParamValidator\TypeDef\IntegerDef\normalizeSettings(), Wikimedia\ParamValidator\TypeDef\LimitDef\validate(), and Wikimedia\ParamValidator\TypeDef\IntegerDef\validate().

◆ PARAM_MAX2

const Wikimedia\ParamValidator\TypeDef\IntegerDef::PARAM_MAX2 = 'param-max2'

(int) Maximum allowed value (high limits)

If not specified, PARAM_MAX will be enforced for all users. Ignored if PARAM_MAX is not set.

ValidationException codes:

  • 'abovehighmaximum': The value was above the allowed maximum. Data:
    • 'min': Allowed minimum, or empty string if there is none.
    • 'max': Allowed (normal) maximum, or empty string if there is none.
    • 'max2': Allowed (high limits) maximum, or empty string if there is none.

Definition at line 70 of file IntegerDef.php.

Referenced by Wikimedia\ParamValidator\TypeDef\IntegerDef\describeSettings(), Wikimedia\ParamValidator\TypeDef\IntegerDef\normalizeSettings(), Wikimedia\ParamValidator\TypeDef\LimitDef\validate(), and Wikimedia\ParamValidator\TypeDef\IntegerDef\validate().

◆ PARAM_MIN

const Wikimedia\ParamValidator\TypeDef\IntegerDef::PARAM_MIN = 'param-min'

(int) Minimum allowed value.

ValidationException codes:

  • 'belowminimum': The value was below the allowed minimum. Data:
    • 'min': Allowed minimum, or empty string if there is none.
    • 'max': Allowed (normal) maximum, or empty string if there is none.
    • 'max2': Allowed (high limits) maximum, or empty string if there is none.

Definition at line 45 of file IntegerDef.php.

Referenced by Wikimedia\ParamValidator\TypeDef\IntegerDef\describeSettings(), and Wikimedia\ParamValidator\TypeDef\IntegerDef\validate().


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