ArrayPathDefinition
Path implements handling of virtual paths This class does not implement real filesystem path handling, but uses virtual paths.
It is primary used in the validation system for handling arrays of input.
Synopsis
Section titled “Synopsis”final class ArrayPathDefinition
| Since | 1.0.0 |
| Source | Util/ArrayPathDefinition.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
| [`flatten(array<int | string, mixed> $array, string |
| [`getFlatKeyNames(array<int | string, mixed> $array, string |
getPartsFromPath(string $path): array{parts: array<int, string>, absolute: bool} | Returns an array with the single parts of the given path. |
| [`getValue(array<int, mixed> | string $partsArrayOrPathString, array<int |
| [`hasValue(array<int, mixed> | string $partsArrayOrPathString, array<int |
| [`setValue(array<int, mixed> | string $partsArrayOrPathString, array<int |
| [`unsetValue(array<int, mixed> | string $partsArrayOrPathString, array<int |
flatten()
Section titled “flatten()”public static function flatten(array<int|string, mixed> $array, string|null $prefix = null): array<int|string, mixed>
Returns the flattened version of an array.
The prefix for the key names (only for internal use).
| Parameter | Type | Description |
|---|---|---|
$array | `array<int“ | string, mixed>` |
$prefix | `string“ | “null` |
Returns array``<``int``|``string``, ``mixed``> — The flattened array.
getFlatKeyNames()
Section titled “getFlatKeyNames()”public static function getFlatKeyNames(array<int|string, mixed> $array, string|null $prefix = null): array<int, string>
Returns the flat key names of an array.
The prefix for the name (only for internal use).
| Parameter | Type | Description |
|---|---|---|
$array | `array<int“ | string, mixed>` |
$prefix | `string“ | “null` |
Returns array``<``int``, ``string``> — The flattened keys.
getPartsFromPath()
Section titled “getPartsFromPath()”public static function getPartsFromPath(string $path): array{parts: array<int, string>, absolute: bool}
Returns an array with the single parts of the given path.
The path.
| Parameter | Type | Description |
|---|---|---|
$path | string | The path. |
Returns array{parts: array<int, string>, absolute: bool} — The parts of the given path.
getValue()
Section titled “getValue()”public static function getValue(array<int, mixed>|string $partsArrayOrPathString, array<int|string, mixed> &$array, mixed $default = null): mixed
Returns the value at the given path.
A default value if the path doesn’t exist in the array.
| Parameter | Type | Description |
|---|---|---|
$partsArrayOrPathString | `array<int, mixed> | “string` |
$array | `array<int“ | string, mixed>` |
$default | mixed | A default value if the path doesn’t exist in the array. |
Returns mixed — The value stored at the given path.
hasValue()
Section titled “hasValue()”public static function hasValue(array<int, mixed>|string $partsArrayOrPathString, array<int|string, mixed> $array): bool
Checks whether the array has a value at the given path.
The array we should operate on.
| Parameter | Type | Description |
|---|---|---|
$partsArrayOrPathString | `array<int, mixed> | “string` |
$array | `array<int“ | string, mixed>` |
Returns bool — Whether the path exists in this array.
setValue()
Section titled “setValue()”public static function setValue(array<int, mixed>|string $partsArrayOrPathString, array<int|string, mixed> &$array, mixed $value): void
Sets the value at the given path.
The value.
| Parameter | Type | Description |
|---|---|---|
$partsArrayOrPathString | `array<int, mixed> | “string` |
$array | `array<int“ | string, mixed>` |
$value | mixed | The value. |
unsetValue()
Section titled “unsetValue()”public static function unsetValue(array<int, mixed>|string $partsArrayOrPathString, array<int|string, mixed> &$array): mixed
Unsets a value at the given path.
The array we should operate on.
| Parameter | Type | Description |
|---|---|---|
$partsArrayOrPathString | `array<int, mixed> | “string` |
$array | `array<int“ | string, mixed>` |
Returns mixed — The previously stored value.