MediaWiki  1.34.0
Wikimedia\ParamValidator\TypeDef\FloatDef Class Reference

Type definition for a floating-point type. More...

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

Public Member Functions

 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...
 
 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...
 
 normalizeSettings (array $settings)
 Normalize a settings array. More...
 

Private Member Functions

 fixLocaleWeirdness ( $value)
 Attempt to fix locale weirdness. More...
 

Additional Inherited Members

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

Detailed Description

Type definition for a floating-point type.

A valid representation consists of:

  • an optional sign (+ or -)
  • a decimal number, using . as the decimal separator and no grouping
  • an optional E-notation suffix: the letter 'e' or 'E', an optional sign, and an integer

Thus, for example, "12", "-.4", "6.022e23", or "+1.7e-10".

The result from validate() is a PHP float.

ValidationException codes:

  • 'badfloat': The value was invalid. No data.
  • 'notfinite': The value was in a valid format, but conversion resulted in infinity or NAN.
Since
1.34 @unstable

Definition at line 29 of file FloatDef.php.

Member Function Documentation

◆ fixLocaleWeirdness()

Wikimedia\ParamValidator\TypeDef\FloatDef::fixLocaleWeirdness (   $value)
private

Attempt to fix locale weirdness.

We don't have any usable number formatting function that's not locale-aware, and setlocale() isn't safe in multithreaded environments. Sigh.

Parameters
string$valueValue to fix
Returns
string

Definition at line 54 of file FloatDef.php.

Referenced by Wikimedia\ParamValidator\TypeDef\FloatDef\stringifyValue().

◆ stringifyValue()

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

References Wikimedia\ParamValidator\TypeDef\FloatDef\fixLocaleWeirdness().

◆ validate()

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


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