Parameter
in package
implements
IParameter, Stringable
Enable safe handling of untrusted data received as string, array, or null values.
Parameter is suitable to encapsulate a value received as a string or array (or NULL) such as query parameters from a web request or database query result. It is used to validate and safely convert inputs to a more useful type.
Table of Contents
Interfaces
- IParameter
- Enable safe handling of untrusted data received as string, array, or null values.
- Stringable
Properties
- $bAllowNull : bool
- $bFrozen : bool
- Whether this parameter is frozen (permanently immutable).
- $bMutable : bool
- Whether this parameter can be modified after creation.
- $bSet : bool
- Whether the value has been set.
- $nuAllowArrayDepth : int|null
- $rKeys : array<int, int|string>
- Array keys for iteration support.
- $xValue : array<string|int, mixed>|string|null
- The encapsulated value - can be a string, array, or null.
Methods
- __construct() : mixed
- __toString() : string
- String representation of the parameter.
- asArray() : array<string|int, mixed>
- Converts the parameter to an array.
- asArrayOrNull() : array<string|int, mixed>|null
- Converts the parameter to an array or returns null.
- asArrayOrString() : array<string|int, mixed>|string
- Returns the parameter as either an array or string.
- asArrayRecursive() : array<string|int, mixed>
- Converts the parameter to an array with all nested IParameter objects unwrapped.
- asArrayRecursiveOrNull() : array<string|int, mixed>|null
- Converts the parameter to a recursively unwrapped array or returns null.
- asArrayRecursiveOrString() : array<string|int, mixed>|string
- Returns the parameter as either a recursively unwrapped array or string.
- asBool() : bool
- Converts the parameter to a boolean value.
- asBoolOrNull() : bool|null
- Converts the parameter to a boolean or returns null.
- asConstant() : string
- Validates that the parameter matches a specific constant value.
- asCurrency() : int
- Converts the parameter to a currency amount in cents.
- asCurrencyOrEmpty() : int|null
- Converts the parameter to a currency amount or returns null for empty strings.
- asCurrencyOrNull() : int|null
- Converts the parameter to a currency amount or returns null.
- asDate() : string
- Converts the parameter to a date string in YYYY-MM-DD format.
- asDateOrNull() : string|null
- asDateTime() : string
- Converts the parameter to a date-time string.
- asDateTimeOrNull() : string|null
- asEmailAddress() : string
- Validates and returns the parameter as an email address.
- asEmailAddressOrEmpty() : string|null
- asEmailAddressOrNull() : string|null
- asEmailUsername() : string
- Validates and returns the parameter as an email username (local part).
- asEmailUsernameOrEmpty() : string|null
- asEmailUsernameOrNull() : string|null
- asExistingDirectory() : string
- Validates that the parameter is a path to an existing directory.
- asExistingDirectoryOrEmpty() : string|null
- asExistingDirectoryOrNull() : string|null
- asExistingFilename() : string
- Validates that the parameter is a path to an existing file.
- asExistingFilenameOrEmpty() : string|null
- asExistingFilenameOrNull() : string|null
- asFloat() : float
- Converts the parameter to a floating-point number.
- asFloatOrEmpty() : float|null
- asFloatOrNull() : float|null
- asFloatRangeClosed() : float
- Validates that the parameter is a float within a closed range (exclusive).
- asFloatRangeClosedOrEmpty() : float|null
- asFloatRangeClosedOrNull() : float|null
- asFloatRangeHalfClosed() : float
- Validates that the parameter is a float within a half-closed range [min, max).
- asFloatRangeHalfClosedOrEmpty() : float|null
- asFloatRangeHalfClosedOrNull() : float|null
- asFloatRangeOpen() : float
- Validates that the parameter is a float within an open range [min, max].
- asFloatRangeOpenOrEmpty() : float|null
- asFloatRangeOpenOrNull() : float|null
- asHostname() : string
- Validates and returns the parameter as a hostname.
- asHostnameOrEmpty() : string|null
- asHostnameOrNull() : string|null
- asInt() : int
- Converts the parameter to an integer.
- asIntOrEmpty() : int|null
- Returns the integer value or null for the empty string.
- asIntOrNull() : int|null
- asIntRangeClosed() : int
- Validates that the parameter is an integer within a closed range (exclusive).
- asIntRangeClosedOrEmpty() : int|null
- asIntRangeClosedOrNull() : int|null
- asIntRangeHalfClosed() : int
- Validates that the parameter is an integer within a half-closed range [min, max).
- asIntRangeHalfClosedOrEmpty() : int|null
- asIntRangeHalfClosedOrNull() : int|null
- asIntRangeOpen() : int
- Validates that the parameter is an integer within an open range [min, max].
- asIntRangeOpenOrEmpty() : int|null
- asIntRangeOpenOrNull() : int|null
- asIP() : string
- Validates and returns the parameter as an IP address (IPv4 or IPv6).
- asIPOrEmpty() : string|null
- asIPOrNull() : string|null
- asIPv4() : string
- Validates and returns the parameter as an IPv4 address.
- asIPv4OrEmpty() : string|null
- asIPv4OrNull() : string|null
- asIPv6() : string
- Validates and returns the parameter as an IPv6 address.
- asIPv6OrEmpty() : string|null
- asIPv6OrNull() : string|null
- asJSON() : string
- Returns the parameter value as a JSON string.
- asKeyword() : string
- Validates that the parameter matches one of the allowed keywords.
- asKeywordOrEmpty() : string|null
- asKeywordOrNull() : string|null
- asMap() : string
- asMapOrEmpty() : string|null
- asMapOrNull() : string|null
- asNonexistentFilename() : string
- Validates that the parameter is a path that does not exist.
- asNonexistentFilenameOrEmpty() : string|null
- asNonexistentFilenameOrNull() : string|null
- asPositiveFloat() : float
- Validates that the parameter is a positive floating-point number (> 0).
- asPositiveFloatOrEmpty() : float|null
- asPositiveFloatOrNull() : float|null
- asPositiveInt() : int
- Validates that the parameter is a positive integer (> 0).
- asPositiveIntOrEmpty() : int|null
- asPositiveIntOrNull() : int|null
- asRoundedFloat() : float
- Converts the parameter to a float rounded to the specified precision.
- asRoundedFloatOrEmpty() : float|null
- asRoundedFloatOrNull() : float|null
- asRoundedInt() : int
- Converts the parameter to an integer after rounding to the specified precision.
- asRoundedIntOrEmpty() : int|null
- asRoundedIntOrNull() : int|null
- asString() : string
- Returns the parameter value as a string.
- asStringOrNull() : string|null
- asTime() : string
- Converts the parameter to a time string in HH:MM:SS format.
- asTimeOrNull() : string|null
- asTimeStamp() : int
- Converts the parameter to a Unix timestamp.
- asTimeStampOrNull() : int|null
- asUnsignedFloat() : float
- Validates that the parameter is a non-negative floating-point number (>= 0).
- asUnsignedFloatOrEmpty() : float|null
- asUnsignedFloatOrNull() : float|null
- asUnsignedInt() : int
- Validates that the parameter is a non-negative integer (>= 0).
- asUnsignedIntOrEmpty() : int|null
- asUnsignedIntOrNull() : int|null
- coerce() : IParameter|null
- current() : Parameter
- Returns the current parameter during array iteration.
- getValue() : array<string|int, mixed>|string|null
- Returns the raw value stored in this parameter.
- has() : bool
- Checks if the parameter array has the specified key.
- indexOrDefault() : Parameter
- Returns a parameter for the given key, or a parameter with the default value.
- indexOrNull() : Parameter|null
- Returns a parameter for the given key, or null if the key doesn't exist.
- is() : bool
- Compares this parameter's value with another value for equality.
- isArray() : bool
- Checks if this parameter contains an array value.
- isBool() : bool
- Checks if this parameter can be converted to a boolean.
- isEmpty() : bool
- Checks if this parameter is empty (null, empty string, or empty array).
- isEmptyString() : bool
- Checks if this parameter is an empty string.
- isFrozen() : bool
- Checks if this parameter is frozen (permanently immutable).
- isMutable() : bool
- Checks if this parameter is currently mutable.
- isNull() : bool
- Checks if this parameter contains a null value.
- isSet() : bool
- Checks if this parameter has been set with a value.
- isString() : bool
- Checks if this parameter contains a string value.
- jsonSerialize() : array<string|int, mixed>|string|null
- Returns the value for JSON serialization.
- key() : int|string
- Returns the current key during array iteration.
- new() : static
- Creates a new parameter with the same configuration but different value.
- next() : void
- Advances the internal pointer during array iteration.
- offsetExists() : bool
- Checks whether an offset exists (ArrayAccess interface).
- offsetGet() : Parameter
- Returns the value at the specified offset (ArrayAccess interface).
- offsetSet() : void
- Sets the value at the specified offset (ArrayAccess interface).
- offsetUnset() : void
- Unsets the value at the specified offset (ArrayAccess interface).
- rewind() : void
- Resets the internal pointer to the beginning during array iteration.
- valid() : bool
- Checks if the current position is valid during array iteration.
- _freeze() : void
- Freezes this parameter, making it permanently immutable.
- _mutate() : void
- Changes the mutability state of this parameter.
- _set() : void
- Sets the value of this parameter.
- checkArray() : void
- Validates that this parameter contains an array value.
- child() : Parameter
- Creates a child parameter with inherited configuration.
- unwrap() : array<string|int, mixed>
- Recursively unwraps nested IParameter objects into plain arrays.
Properties
$bAllowNull read-only
private
bool
$bAllowNull
= true
$bFrozen
Whether this parameter is frozen (permanently immutable).
private
bool
$bFrozen
= false
$bMutable
Whether this parameter can be modified after creation.
private
bool
$bMutable
= false
$bSet
Whether the value has been set.
private
bool
$bSet
= false
$nuAllowArrayDepth read-only
private
int|null
$nuAllowArrayDepth
= null
$rKeys
Array keys for iteration support.
private
array<int, int|string>
$rKeys
= []
$xValue
The encapsulated value - can be a string, array, or null.
private
array<string|int, mixed>|string|null
$xValue
Methods
__construct()
public
__construct(array<string|int, mixed>|string|IParameter|null $xValue[, bool $bAllowNull = true ][, int|null $nuAllowArrayDepth = null ]) : mixed
Parameters
- $xValue : array<string|int, mixed>|string|IParameter|null
-
The value to encapsulate.
- $bAllowNull : bool = true
-
If true, null is allowed as a value. If false, an exception is thrown when null is encountered.
- $nuAllowArrayDepth : int|null = null
-
If not null, the maximum levels of array nesting that are allowed. 0 means arrays are not allowed, 1 means flat arrays are allowed, 2 means arrays of arrays are allowed, etc.
__toString()
String representation of the parameter.
public
__toString() : string
Tags
Return values
string —The parameter value as a string
asArray()
Converts the parameter to an array.
public
asArray([string|null $i_nstError = null ]) : array<string|int, mixed>
Parameters
- $i_nstError : string|null = null
-
Optional custom error message
Tags
Return values
array<string|int, mixed> —The parameter value as an array
asArrayOrNull()
Converts the parameter to an array or returns null.
public
asArrayOrNull() : array<string|int, mixed>|null
Tags
Return values
array<string|int, mixed>|null —The parameter value as an array, or null if the parameter is null
asArrayOrString()
Returns the parameter as either an array or string.
public
asArrayOrString() : array<string|int, mixed>|string
Tags
Return values
array<string|int, mixed>|string —The parameter value as an array if it's an array, otherwise as a string
asArrayRecursive()
Converts the parameter to an array with all nested IParameter objects unwrapped.
public
asArrayRecursive([string|null $i_nstError = null ]) : array<string|int, mixed>
Parameters
- $i_nstError : string|null = null
-
Optional custom error message
Tags
Return values
array<string|int, mixed> —The parameter value as an array with all IParameter objects converted to their values
asArrayRecursiveOrNull()
Converts the parameter to a recursively unwrapped array or returns null.
public
asArrayRecursiveOrNull() : array<string|int, mixed>|null
Tags
Return values
array<string|int, mixed>|null —The recursively unwrapped array, or null if the parameter is null
asArrayRecursiveOrString()
Returns the parameter as either a recursively unwrapped array or string.
public
asArrayRecursiveOrString() : array<string|int, mixed>|string
Tags
Return values
array<string|int, mixed>|string —The recursively unwrapped array if it's an array, otherwise as a string
asBool()
Converts the parameter to a boolean value.
public
asBool() : bool
Note: This method treats null as false. If you need to distinguish between null and false, use asBoolOrNull() instead.
Tags
Return values
bool —The parameter value as a boolean
asBoolOrNull()
Converts the parameter to a boolean or returns null.
public
asBoolOrNull() : bool|null
Unlike the other asTypeOrNull() methods, asBoolOrNull() really only changes how a null value is handled; asBoolOrNull() returns null, whereas asBool() coerces null to false. So asBoolOrNull() is more of a tri-bool.
Tags
Return values
bool|null —The parameter value as a boolean, or null if the parameter is null
asConstant()
Validates that the parameter matches a specific constant value.
public
asConstant(string $i_stConstant) : string
Parameters
- $i_stConstant : string
-
The expected constant value
Tags
Return values
string —The parameter value (which matches the constant)
asCurrency()
Converts the parameter to a currency amount in cents.
public
asCurrency() : int
Tags
Return values
int —The currency amount in cents (e.g., $1.23 becomes 123)
asCurrencyOrEmpty()
Converts the parameter to a currency amount or returns null for empty strings.
public
asCurrencyOrEmpty() : int|null
Tags
Return values
int|null —The currency amount in cents, or null if the parameter is an empty string
asCurrencyOrNull()
Converts the parameter to a currency amount or returns null.
public
asCurrencyOrNull() : int|null
Tags
Return values
int|null —The currency amount in cents, or null if the parameter is null
asDate()
Converts the parameter to a date string in YYYY-MM-DD format.
public
asDate() : string
Tags
Return values
string —The date in YYYY-MM-DD format
asDateOrNull()
public
asDateOrNull() : string|null
Return values
string|nullasDateTime()
Converts the parameter to a date-time string.
public
asDateTime() : string
Tags
Return values
string —The date and time in a standard format
asDateTimeOrNull()
public
asDateTimeOrNull() : string|null
Return values
string|nullasEmailAddress()
Validates and returns the parameter as an email address.
public
asEmailAddress() : string
Tags
Return values
string —The validated email address
asEmailAddressOrEmpty()
public
asEmailAddressOrEmpty() : string|null
Return values
string|nullasEmailAddressOrNull()
public
asEmailAddressOrNull() : string|null
Return values
string|nullasEmailUsername()
Validates and returns the parameter as an email username (local part).
public
asEmailUsername() : string
Tags
Return values
string —The validated email username (part before @)
asEmailUsernameOrEmpty()
public
asEmailUsernameOrEmpty() : string|null
Return values
string|nullasEmailUsernameOrNull()
public
asEmailUsernameOrNull() : string|null
Return values
string|nullasExistingDirectory()
Validates that the parameter is a path to an existing directory.
public
asExistingDirectory() : string
Tags
Return values
string —The validated directory path
asExistingDirectoryOrEmpty()
public
asExistingDirectoryOrEmpty() : string|null
Return values
string|nullasExistingDirectoryOrNull()
public
asExistingDirectoryOrNull() : string|null
Return values
string|nullasExistingFilename()
Validates that the parameter is a path to an existing file.
public
asExistingFilename() : string
Tags
Return values
string —The validated file path
asExistingFilenameOrEmpty()
public
asExistingFilenameOrEmpty() : string|null
Return values
string|nullasExistingFilenameOrNull()
public
asExistingFilenameOrNull() : string|null
Return values
string|nullasFloat()
Converts the parameter to a floating-point number.
public
asFloat() : float
Tags
Return values
float —The parameter value as a float
asFloatOrEmpty()
public
asFloatOrEmpty() : float|null
Return values
float|nullasFloatOrNull()
public
asFloatOrNull() : float|null
Return values
float|nullasFloatRangeClosed()
Validates that the parameter is a float within a closed range (exclusive).
public
asFloatRangeClosed(float $i_fMin, float $i_fMax) : float
Parameters
- $i_fMin : float
-
The minimum allowed value (exclusive)
- $i_fMax : float
-
The maximum allowed value (exclusive)
Tags
Return values
float —The parameter value as a float
asFloatRangeClosedOrEmpty()
public
asFloatRangeClosedOrEmpty(float $i_fMin, float $i_fMax) : float|null
Parameters
- $i_fMin : float
- $i_fMax : float
Return values
float|nullasFloatRangeClosedOrNull()
public
asFloatRangeClosedOrNull(float $i_fMin, float $i_fMax) : float|null
Parameters
- $i_fMin : float
- $i_fMax : float
Return values
float|nullasFloatRangeHalfClosed()
Validates that the parameter is a float within a half-closed range [min, max).
public
asFloatRangeHalfClosed(float $i_fMin, float $i_fMax) : float
Parameters
- $i_fMin : float
-
The minimum allowed value (inclusive)
- $i_fMax : float
-
The maximum allowed value (exclusive)
Tags
Return values
float —The parameter value as a float
asFloatRangeHalfClosedOrEmpty()
public
asFloatRangeHalfClosedOrEmpty(float $i_fMin, float $i_fMax) : float|null
Parameters
- $i_fMin : float
- $i_fMax : float
Return values
float|nullasFloatRangeHalfClosedOrNull()
public
asFloatRangeHalfClosedOrNull(float $i_fMin, float $i_fMax) : float|null
Parameters
- $i_fMin : float
- $i_fMax : float
Return values
float|nullasFloatRangeOpen()
Validates that the parameter is a float within an open range [min, max].
public
asFloatRangeOpen(float $i_fMin, float $i_fMax) : float
Parameters
- $i_fMin : float
-
The minimum allowed value (inclusive)
- $i_fMax : float
-
The maximum allowed value (inclusive)
Tags
Return values
float —The parameter value as a float
asFloatRangeOpenOrEmpty()
public
asFloatRangeOpenOrEmpty(float $i_fMin, float $i_fMax) : float|null
Parameters
- $i_fMin : float
- $i_fMax : float
Return values
float|nullasFloatRangeOpenOrNull()
public
asFloatRangeOpenOrNull(float $i_fMin, float $i_fMax) : float|null
Parameters
- $i_fMin : float
- $i_fMax : float
Return values
float|nullasHostname()
Validates and returns the parameter as a hostname.
public
asHostname() : string
Tags
Return values
string —The validated hostname
asHostnameOrEmpty()
public
asHostnameOrEmpty() : string|null
Return values
string|nullasHostnameOrNull()
public
asHostnameOrNull() : string|null
Return values
string|nullasInt()
Converts the parameter to an integer.
public
asInt() : int
Tags
Return values
int —The parameter value as an integer
asIntOrEmpty()
Returns the integer value or null for the empty string.
public
asIntOrEmpty() : int|null
Return values
int|nullasIntOrNull()
public
asIntOrNull() : int|null
Return values
int|nullasIntRangeClosed()
Validates that the parameter is an integer within a closed range (exclusive).
public
asIntRangeClosed(int $i_iMin, int $i_iMax) : int
Parameters
- $i_iMin : int
-
The minimum allowed value (exclusive)
- $i_iMax : int
-
The maximum allowed value (exclusive)
Tags
Return values
int —The parameter value as an integer
asIntRangeClosedOrEmpty()
public
asIntRangeClosedOrEmpty(int $i_iMin, int $i_iMax) : int|null
Parameters
- $i_iMin : int
- $i_iMax : int
Return values
int|nullasIntRangeClosedOrNull()
public
asIntRangeClosedOrNull(int $i_iMin, int $i_iMax) : int|null
Parameters
- $i_iMin : int
- $i_iMax : int
Return values
int|nullasIntRangeHalfClosed()
Validates that the parameter is an integer within a half-closed range [min, max).
public
asIntRangeHalfClosed(int $i_iMin, int $i_iMax) : int
Parameters
- $i_iMin : int
-
The minimum allowed value (inclusive)
- $i_iMax : int
-
The maximum allowed value (exclusive)
Tags
Return values
int —The parameter value as an integer
asIntRangeHalfClosedOrEmpty()
public
asIntRangeHalfClosedOrEmpty(int $i_iMin, int $i_iMax) : int|null
Parameters
- $i_iMin : int
- $i_iMax : int
Return values
int|nullasIntRangeHalfClosedOrNull()
public
asIntRangeHalfClosedOrNull(int $i_iMin, int $i_iMax) : int|null
Parameters
- $i_iMin : int
- $i_iMax : int
Return values
int|nullasIntRangeOpen()
Validates that the parameter is an integer within an open range [min, max].
public
asIntRangeOpen(int $i_iMin, int $i_iMax) : int
Parameters
- $i_iMin : int
-
The minimum allowed value (inclusive)
- $i_iMax : int
-
The maximum allowed value (inclusive)
Tags
Return values
int —The parameter value as an integer
asIntRangeOpenOrEmpty()
public
asIntRangeOpenOrEmpty(int $i_iMin, int $i_iMax) : int|null
Parameters
- $i_iMin : int
- $i_iMax : int
Return values
int|nullasIntRangeOpenOrNull()
public
asIntRangeOpenOrNull(int $i_iMin, int $i_iMax) : int|null
Parameters
- $i_iMin : int
- $i_iMax : int
Return values
int|nullasIP()
Validates and returns the parameter as an IP address (IPv4 or IPv6).
public
asIP() : string
Tags
Return values
string —The validated IP address
asIPOrEmpty()
public
asIPOrEmpty() : string|null
Return values
string|nullasIPOrNull()
public
asIPOrNull() : string|null
Return values
string|nullasIPv4()
Validates and returns the parameter as an IPv4 address.
public
asIPv4() : string
Tags
Return values
string —The validated IPv4 address
asIPv4OrEmpty()
public
asIPv4OrEmpty() : string|null
Return values
string|nullasIPv4OrNull()
public
asIPv4OrNull() : string|null
Return values
string|nullasIPv6()
Validates and returns the parameter as an IPv6 address.
public
asIPv6() : string
Tags
Return values
string —The validated IPv6 address
asIPv6OrEmpty()
public
asIPv6OrEmpty() : string|null
Return values
string|nullasIPv6OrNull()
public
asIPv6OrNull() : string|null
Return values
string|nullasJSON()
Returns the parameter value as a JSON string.
public
asJSON() : string
This is primarily intended for debugging purposes.
Tags
Return values
string —The parameter value encoded as JSON
asKeyword()
Validates that the parameter matches one of the allowed keywords.
public
asKeyword(array<int, string> $i_rKeywords) : string
Parameters
- $i_rKeywords : array<int, string>
-
List of allowable keywords
Tags
Return values
string —The parameter value (which matches one of the keywords)
asKeywordOrEmpty()
public
asKeywordOrEmpty(array<int, string> $i_rKeywords) : string|null
Parameters
- $i_rKeywords : array<int, string>
-
List of allowable keywords.
Return values
string|nullasKeywordOrNull()
public
asKeywordOrNull(array<int, string> $i_rKeywords) : string|null
Parameters
- $i_rKeywords : array<int, string>
-
List of allowable keywords.
Return values
string|nullasMap()
public
asMap(array<string, mixed> $i_rMap) : string
Parameters
- $i_rMap : array<string, mixed>
Return values
string —The mapped value for the key specified by this parameter.
asMapOrEmpty()
public
asMapOrEmpty(array<string, mixed> $i_rMap) : string|null
Parameters
- $i_rMap : array<string, mixed>
Return values
string|null —The mapped value for the key specified by this parameter, or null if the parameter is the empty string.
asMapOrNull()
public
asMapOrNull(array<string, mixed> $i_rMap) : string|null
Parameters
- $i_rMap : array<string, mixed>
Return values
string|null —The mapped value for the key specified by this parameter, or null.
asNonexistentFilename()
Validates that the parameter is a path that does not exist.
public
asNonexistentFilename() : string
Tags
Return values
string —The validated path
asNonexistentFilenameOrEmpty()
public
asNonexistentFilenameOrEmpty() : string|null
Return values
string|nullasNonexistentFilenameOrNull()
public
asNonexistentFilenameOrNull() : string|null
Return values
string|nullasPositiveFloat()
Validates that the parameter is a positive floating-point number (> 0).
public
asPositiveFloat() : float
Tags
Return values
float —The parameter value as a positive float
asPositiveFloatOrEmpty()
public
asPositiveFloatOrEmpty() : float|null
Return values
float|nullasPositiveFloatOrNull()
public
asPositiveFloatOrNull() : float|null
Return values
float|nullasPositiveInt()
Validates that the parameter is a positive integer (> 0).
public
asPositiveInt() : int
Tags
Return values
int —The parameter value as a positive integer
asPositiveIntOrEmpty()
public
asPositiveIntOrEmpty() : int|null
Return values
int|nullasPositiveIntOrNull()
public
asPositiveIntOrNull() : int|null
Return values
int|nullasRoundedFloat()
Converts the parameter to a float rounded to the specified precision.
public
asRoundedFloat([int $i_iPrecision = 0 ]) : float
Parameters
- $i_iPrecision : int = 0
-
Number of decimal places to round to (default: 0)
Tags
Return values
float —The rounded float value
asRoundedFloatOrEmpty()
public
asRoundedFloatOrEmpty([int $i_iPrecision = 0 ]) : float|null
Parameters
- $i_iPrecision : int = 0
Return values
float|nullasRoundedFloatOrNull()
public
asRoundedFloatOrNull([int $i_iPrecision = 0 ]) : float|null
Parameters
- $i_iPrecision : int = 0
Return values
float|nullasRoundedInt()
Converts the parameter to an integer after rounding to the specified precision.
public
asRoundedInt([int $i_iPrecision = 0 ]) : int
Parameters
- $i_iPrecision : int = 0
-
Number of decimal places before rounding (default: 0)
Tags
Return values
int —The rounded integer value
asRoundedIntOrEmpty()
public
asRoundedIntOrEmpty([int $i_iPrecision = 0 ]) : int|null
Parameters
- $i_iPrecision : int = 0
Return values
int|nullasRoundedIntOrNull()
public
asRoundedIntOrNull([int $i_iPrecision = 0 ]) : int|null
Parameters
- $i_iPrecision : int = 0
Return values
int|nullasString()
Returns the parameter value as a string.
public
asString() : string
Tags
Return values
string —The parameter value as a string
asStringOrNull()
public
asStringOrNull() : string|null
Return values
string|nullasTime()
Converts the parameter to a time string in HH:MM:SS format.
public
asTime() : string
Tags
Return values
string —The time in HH:MM:SS format
asTimeOrNull()
public
asTimeOrNull() : string|null
Return values
string|nullasTimeStamp()
Converts the parameter to a Unix timestamp.
public
asTimeStamp() : int
Tags
Return values
int —The Unix timestamp
asTimeStampOrNull()
public
asTimeStampOrNull() : int|null
Return values
int|nullasUnsignedFloat()
Validates that the parameter is a non-negative floating-point number (>= 0).
public
asUnsignedFloat() : float
Tags
Return values
float —The parameter value as a non-negative float
asUnsignedFloatOrEmpty()
public
asUnsignedFloatOrEmpty() : float|null
Return values
float|nullasUnsignedFloatOrNull()
public
asUnsignedFloatOrNull() : float|null
Return values
float|nullasUnsignedInt()
Validates that the parameter is a non-negative integer (>= 0).
public
asUnsignedInt() : int
Tags
Return values
int —The parameter value as a non-negative integer
asUnsignedIntOrEmpty()
public
asUnsignedIntOrEmpty() : int|null
Return values
int|nullasUnsignedIntOrNull()
public
asUnsignedIntOrNull() : int|null
Return values
int|nullcoerce()
public
static coerce(mixed $i_xValue) : IParameter|null
Parameters
- $i_xValue : mixed
Return values
IParameter|null —Makes sure a value is a Parameter or null. Useful for handling arbitrary default values while passing through Parameter values unmodified.
current()
Returns the current parameter during array iteration.
public
current() : Parameter
Tags
Return values
Parameter —The current parameter
getValue()
Returns the raw value stored in this parameter.
public
getValue() : array<string|int, mixed>|string|null
Return values
array<string|int, mixed>|string|null —The raw parameter value
has()
Checks if the parameter array has the specified key.
public
has(int|string $key) : bool
Parameters
- $key : int|string
-
The key to check for
Tags
Return values
bool —True if the key exists, false otherwise
indexOrDefault()
Returns a parameter for the given key, or a parameter with the default value.
public
indexOrDefault(int|string $key, array<string|int, mixed>|string|null $default) : Parameter
Parameters
- $key : int|string
-
The array key to access
- $default : array<string|int, mixed>|string|null
-
The default value if the key doesn't exist
Tags
Return values
Parameter —A Parameter containing either the key's value or the default
indexOrNull()
Returns a parameter for the given key, or null if the key doesn't exist.
public
indexOrNull(int|string $key) : Parameter|null
Parameters
- $key : int|string
-
The array key to access
Tags
Return values
Parameter|null —A Parameter for the key's value, or null if the key doesn't exist
is()
Compares this parameter's value with another value for equality.
public
is(array<string|int, mixed>|int|string|float|bool|IParameter|null $i_xValue) : bool
This method handles type-aware comparisons including boolean validation, recursive array comparison, and proper null handling.
Parameters
- $i_xValue : array<string|int, mixed>|int|string|float|bool|IParameter|null
-
The value to compare against
Return values
bool —True if the values are equal, false otherwise
isArray()
Checks if this parameter contains an array value.
public
isArray() : bool
Return values
bool —True if the parameter is an array, false otherwise
isBool()
Checks if this parameter can be converted to a boolean.
public
isBool() : bool
Return values
bool —True if the parameter can be parsed as a boolean, false otherwise
isEmpty()
Checks if this parameter is empty (null, empty string, or empty array).
public
isEmpty() : bool
Return values
bool —True if the parameter is empty, false otherwise
isEmptyString()
Checks if this parameter is an empty string.
public
isEmptyString() : bool
Return values
bool —True if the parameter is an empty string, false otherwise
isFrozen()
Checks if this parameter is frozen (permanently immutable).
public
isFrozen() : bool
Return values
bool —True if the parameter is frozen, false otherwise
isMutable()
Checks if this parameter is currently mutable.
public
isMutable() : bool
Return values
bool —True if the parameter can be modified, false otherwise
isNull()
Checks if this parameter contains a null value.
public
isNull() : bool
Return values
bool —True if the parameter is null, false otherwise
isSet()
Checks if this parameter has been set with a value.
public
isSet() : bool
Return values
bool —Always returns true for immutable parameters
isString()
Checks if this parameter contains a string value.
public
isString() : bool
Return values
bool —True if the parameter is a string, false otherwise
jsonSerialize()
Returns the value for JSON serialization.
public
jsonSerialize() : array<string|int, mixed>|string|null
Return values
array<string|int, mixed>|string|null —The value suitable for JSON encoding
key()
Returns the current key during array iteration.
public
key() : int|string
Tags
Return values
int|string —The current array key
new()
Creates a new parameter with the same configuration but different value.
public
new(array<string|int, mixed>|bool|float|int|string|IParameter|null $xValue) : static
Parameters
- $xValue : array<string|int, mixed>|bool|float|int|string|IParameter|null
-
The value for the new parameter
Return values
static —A new parameter instance with the same configuration
next()
Advances the internal pointer during array iteration.
public
next() : void
Tags
offsetExists()
Checks whether an offset exists (ArrayAccess interface).
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
-
The offset to check (must be int or string)
Tags
Return values
bool —True if the offset exists, false otherwise
offsetGet()
Returns the value at the specified offset (ArrayAccess interface).
public
offsetGet(mixed $offset) : Parameter
Parameters
- $offset : mixed
-
The offset to retrieve (must be int or string)
Tags
Return values
Parameter —The parameter at the specified offset
offsetSet()
Sets the value at the specified offset (ArrayAccess interface).
public
offsetSet(mixed $offset, mixed $value) : void
Always throws LogicException since Parameters are immutable.
Parameters
- $offset : mixed
-
The offset to set (must be int or string)
- $value : mixed
-
The value to set
Tags
offsetUnset()
Unsets the value at the specified offset (ArrayAccess interface).
public
offsetUnset(mixed $offset) : void
Always throws LogicException since Parameters are immutable.
Parameters
- $offset : mixed
-
The offset to unset (must be int or string)
Tags
rewind()
Resets the internal pointer to the beginning during array iteration.
public
rewind() : void
Tags
valid()
Checks if the current position is valid during array iteration.
public
valid() : bool
Tags
Return values
bool —True if the current position is valid, false otherwise
_freeze()
Freezes this parameter, making it permanently immutable.
protected
_freeze() : void
_mutate()
Changes the mutability state of this parameter.
protected
_mutate(bool $i_bMutable) : void
Parameters
- $i_bMutable : bool
-
Whether the parameter should be mutable
Tags
_set()
Sets the value of this parameter.
protected
_set(array<string|int, mixed>|bool|float|int|string|IParameter|null $i_xValue) : void
Parameters
- $i_xValue : array<string|int, mixed>|bool|float|int|string|IParameter|null
-
The value to set
Tags
checkArray()
Validates that this parameter contains an array value.
private
checkArray() : void
Tags
child()
Creates a child parameter with inherited configuration.
private
child(array<string|int, mixed>|bool|float|int|string|IParameter|null $i_xValue) : Parameter
Parameters
- $i_xValue : array<string|int, mixed>|bool|float|int|string|IParameter|null
-
The value for the child parameter
Return values
Parameter —A new Parameter instance with inherited configuration
unwrap()
Recursively unwraps nested IParameter objects into plain arrays.
private
static unwrap(array<string|int, mixed>|IParameter $i_xValue) : array<string|int, mixed>
Parameters
- $i_xValue : array<string|int, mixed>|IParameter
-
The value to unwrap
Return values
array<string|int, mixed> —The unwrapped array with all IParameter objects converted to their values