param

ParameterSet
in package
implements IParameterSet

A collection of named parameters with support for defaults, allowed keys, and filtering.

ParameterSet provides a type-safe way to manage collections of parameters, commonly used for handling web request data, configuration options, or database query results. It supports default values, key filtering, and various subset operations.

Table of Contents

Interfaces

IParameterSet

Properties

$bMutable  : bool
Whether this parameter set can be modified after creation.
$mapDefaults  : Map<string, IParameter>
Map of parameter keys to their default values.
$mapParameters  : Map<string, IParameter>
Map of parameter keys to their values.
$setAllowedKeys  : Set<string|int, string>
Set of keys that are allowed in this parameter set.
$setIgnoredKeys  : Set<string|int, string>
Set of keys that were ignored due to not being in the allowed keys.

Methods

__construct()  : mixed
Creates a new ParameterSet with optional initial parameters, defaults, and allowed keys.
addAllowedKey()  : void
Adds a key to the set of allowed keys.
addAllowedKeys()  : void
Adds multiple keys to the set of allowed keys.
addDefault()  : void
Adds a default value for a key (throws exception if default already exists).
addDefaults()  : void
Adds multiple default values (throws exception if any defaults already exist).
addParameter()  : void
Adds a parameter value (throws exception if parameter already exists).
addParameters()  : void
Adds multiple parameters (throws exception if any parameters already exist).
get()  : IParameter|null
Gets a parameter by key, falling back to defaults and then the provided default.
getAllowedKeys()  : array<int, string>|null
Returns the list of allowed keys, or null if all keys are allowed.
getEx()  : IParameter
Gets a parameter by key, throwing an exception if not found.
getIgnoredKeys()  : array<int, string>
Returns the list of keys that were ignored due to not being in allowed keys.
getValues()  : array<int|string, array<string|int, mixed>|string|null>
Returns all parameter values as an associative array.
has()  : bool
Checks if all specified keys exist (either as parameters or defaults).
iter()  : Generator<string, IParameter>
Returns a generator that yields all key-parameter pairs.
jsonSerialize()  : array<int|string, array<string|int, mixed>|bool|float|int|string|null>
Returns the parameter set as an array suitable for JSON serialization.
listKeys()  : array<int, string>
Returns a list of all available keys (parameters + defaults, filtered by allowed keys).
offsetExists()  : bool
Checks whether an offset exists (ArrayAccess interface).
offsetGet()  : IParameter
Returns the parameter at the specified offset (ArrayAccess interface).
offsetSet()  : void
Sets the parameter at the specified offset (ArrayAccess interface).
offsetUnset()  : void
Unsets the parameter at the specified offset (ArrayAccess interface).
setDefault()  : void
Sets or updates a default value for a key.
setMutable()  : void
Sets the mutability state of this parameter set.
setParameter()  : void
Sets or updates a parameter value.
subsetByKeyPrefix()  : static
Creates a subset containing only parameters with keys that start with the given prefix.
subsetByKeys()  : static
Creates a subset containing only parameters whose keys match the filter function.
subsetByRegExp()  : static
Creates a subset containing only parameters with keys that match the regular expression.
testKeys()  : array<int, string>
Returns which of the specified keys actually exist in this parameter set.
unset()  : void
Removes parameters (and optionally their defaults) from the set.
isKeyAllowed()  : bool
Checks if a key is allowed based on the allowed keys set.

Properties

$bMutable

Whether this parameter set can be modified after creation.

private bool $bMutable = false

$setAllowedKeys

Set of keys that are allowed in this parameter set.

private Set<string|int, string> $setAllowedKeys

$setIgnoredKeys

Set of keys that were ignored due to not being in the allowed keys.

private Set<string|int, string> $setIgnoredKeys

Methods

__construct()

Creates a new ParameterSet with optional initial parameters, defaults, and allowed keys.

public __construct([iterable<int|string, array<int, string|IParameter>|string|IParameter>|null $i_itParameters = null ][, iterable<int|string, array<int, string|IParameter>|string|IParameter>|null $i_itDefaults = null ][, iterable<string|int, int|string>|null $i_itAllowedKeys = null ]) : mixed
Parameters
$i_itParameters : iterable<int|string, array<int, string|IParameter>|string|IParameter>|null = null

Initial parameters

$i_itDefaults : iterable<int|string, array<int, string|IParameter>|string|IParameter>|null = null

Default values

$i_itAllowedKeys : iterable<string|int, int|string>|null = null

Keys that are allowed (null means all keys allowed)

Tags
noinspection

PhpDocSignatureInspection iterable is broken in PhpStorm

addAllowedKey()

Adds a key to the set of allowed keys.

public addAllowedKey(string $i_stKey) : void
Parameters
$i_stKey : string

The key to allow

addAllowedKeys()

Adds multiple keys to the set of allowed keys.

public addAllowedKeys([iterable<string|int, int|string>|null $i_itAllowedKeys = null ]) : void
Parameters
$i_itAllowedKeys : iterable<string|int, int|string>|null = null

The keys to allow

Tags
noinspection

PhpDocSignatureInspection iterable is broken in PhpStorm

addDefault()

Adds a default value for a key (throws exception if default already exists).

public addDefault(string $i_stKey[, array<string|int, mixed>|string|IParameter|null $i_xValue = null ]) : void
Parameters
$i_stKey : string

The parameter key

$i_xValue : array<string|int, mixed>|string|IParameter|null = null

The default value

Tags
throws
InvalidArgumentException

If a default for this key already exists

addDefaults()

Adds multiple default values (throws exception if any defaults already exist).

public addDefaults([iterable<int|string, array<string|int, mixed>|string|IParameter|null>|null $i_itDefaults = null ]) : void
Parameters
$i_itDefaults : iterable<int|string, array<string|int, mixed>|string|IParameter|null>|null = null

The defaults to add

Tags
throws
InvalidArgumentException

If any defaults for the keys already exist

noinspection

PhpDocSignatureInspection iterable is broken in PhpStorm

addParameter()

Adds a parameter value (throws exception if parameter already exists).

public addParameter(string $i_stKey[, array<string|int, mixed>|string|IParameter|null $i_xValue = null ]) : void
Parameters
$i_stKey : string

The parameter key

$i_xValue : array<string|int, mixed>|string|IParameter|null = null

The parameter value

Tags
throws
InvalidArgumentException

If a parameter for this key already exists

addParameters()

Adds multiple parameters (throws exception if any parameters already exist).

public addParameters([iterable<int|string, array<string|int, mixed>|string|IParameter|null>|null $i_itParameters = null ]) : void
Parameters
$i_itParameters : iterable<int|string, array<string|int, mixed>|string|IParameter|null>|null = null

The parameters to add

Tags
throws
InvalidArgumentException

If any parameters for the keys already exist

noinspection

PhpDocSignatureInspection iterable is broken in PhpStorm

get()

Gets a parameter by key, falling back to defaults and then the provided default.

public get(string $i_stKey[, mixed $i_xDefault = null ]) : IParameter|null
Parameters
$i_stKey : string

The parameter key

$i_xDefault : mixed = null

The default value if parameter and default are not found

Return values
IParameter|null

The parameter, or null if not found and no default provided

getAllowedKeys()

Returns the list of allowed keys, or null if all keys are allowed.

public getAllowedKeys() : array<int, string>|null
Return values
array<int, string>|null

The allowed keys, or null if no restrictions

getEx()

Gets a parameter by key, throwing an exception if not found.

public getEx(string $i_stKey) : IParameter
Parameters
$i_stKey : string

The parameter key

Tags
throws
InvalidArgumentException

If the key is not found

Return values
IParameter

The parameter

getIgnoredKeys()

Returns the list of keys that were ignored due to not being in allowed keys.

public getIgnoredKeys() : array<int, string>
Return values
array<int, string>

The ignored keys

getValues()

Returns all parameter values as an associative array.

public getValues() : array<int|string, array<string|int, mixed>|string|null>

Arrays are recursively unwrapped, other values are returned as-is.

Return values
array<int|string, array<string|int, mixed>|string|null>

The parameter values

has()

Checks if all specified keys exist (either as parameters or defaults).

public has(string ...$i_rstKeys) : bool
Parameters
$i_rstKeys : string

The keys to check

Return values
bool

True if all keys exist, false otherwise

iter()

Returns a generator that yields all key-parameter pairs.

public iter() : Generator<string, IParameter>
Return values
Generator<string, IParameter>

Generator yielding key => parameter pairs

jsonSerialize()

Returns the parameter set as an array suitable for JSON serialization.

public jsonSerialize() : array<int|string, array<string|int, mixed>|bool|float|int|string|null>
Return values
array<int|string, array<string|int, mixed>|bool|float|int|string|null>

The JSON-serializable array

listKeys()

Returns a list of all available keys (parameters + defaults, filtered by allowed keys).

public listKeys() : array<int, string>
Return values
array<int, string>

The available keys

offsetExists()

Checks whether an offset exists (ArrayAccess interface).

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed

The offset to check (string key or array of keys)

Return values
bool

True if the offset(s) exist, false otherwise

offsetGet()

Returns the parameter at the specified offset (ArrayAccess interface).

public offsetGet(mixed $offset) : IParameter
Parameters
$offset : mixed

The offset to retrieve (must be a string key)

Tags
throws
InvalidArgumentException

If the offset is null or the key is not found

Return values
IParameter

The parameter at the specified offset

offsetSet()

Sets the parameter at the specified offset (ArrayAccess interface).

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed

The offset to set (must be a string key)

$value : mixed

The parameter value to set

Tags
throws
LogicException

If the offset is null

offsetUnset()

Unsets the parameter at the specified offset (ArrayAccess interface).

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed

The offset to unset (string key or array of keys)

Tags
throws
InvalidArgumentException

If the offset is null

throws
LogicException

If the set is not mutable

setDefault()

Sets or updates a default value for a key.

public setDefault(string $i_stKey, array<string|int, mixed>|string|IParameter|null $i_xValue) : void
Parameters
$i_stKey : string

The parameter key

$i_xValue : array<string|int, mixed>|string|IParameter|null

The default value

Tags
throws
LogicException

If trying to reset a default in an immutable set

setMutable()

Sets the mutability state of this parameter set.

public setMutable(bool $i_bMutable) : void
Parameters
$i_bMutable : bool

Whether the parameter set should be mutable

setParameter()

Sets or updates a parameter value.

public setParameter(string $i_stKey, array<string|int, mixed>|string|IParameter|null $i_xValue) : void
Parameters
$i_stKey : string

The parameter key

$i_xValue : array<string|int, mixed>|string|IParameter|null

The parameter value

Tags
throws
InvalidArgumentException

If trying to set a parameter in an immutable set

subsetByKeyPrefix()

Creates a subset containing only parameters with keys that start with the given prefix.

public subsetByKeyPrefix(string $i_stPrefix) : static
Parameters
$i_stPrefix : string

The key prefix to filter by

Return values
static

A new ParameterSet containing only matching parameters

subsetByKeys()

Creates a subset containing only parameters whose keys match the filter function.

public subsetByKeys(callable(string): bool $i_fnFilter) : static
Parameters
$i_fnFilter : callable(string): bool

Function that returns true for keys to include

Return values
static

A new ParameterSet containing only matching parameters

subsetByRegExp()

Creates a subset containing only parameters with keys that match the regular expression.

public subsetByRegExp(string $i_reFilter) : static
Parameters
$i_reFilter : string

The regular expression to match keys against

Return values
static

A new ParameterSet containing only matching parameters

testKeys()

Returns which of the specified keys actually exist in this parameter set.

public testKeys(string ...$i_rstKeys) : array<int, string>
Parameters
$i_rstKeys : string

The keys to test

Return values
array<int, string>

The keys that exist (subset of the input keys)

unset()

Removes parameters (and optionally their defaults) from the set.

public unset(string|iterable<string|int, string> $i_keys[, bool $i_bAlsoDropDefault = false ]) : void
Parameters
$i_keys : string|iterable<string|int, string>

The key(s) to remove

$i_bAlsoDropDefault : bool = false

Whether to also remove default values

Tags
throws
LogicException

If the set is not mutable

noinspection

PhpDocSignatureInspection

isKeyAllowed()

Checks if a key is allowed based on the allowed keys set.

private isKeyAllowed(string $i_stKey) : bool
Parameters
$i_stKey : string

The key to check

Return values
bool

True if the key is allowed (or if no allowed keys are set), false otherwise


        
On this page

Search results