Skip to content

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.

final class ArrayPathDefinition

Since1.0.0
SourceUtil/ArrayPathDefinition.php
MethodDescription
[`flatten(array<intstring, mixed> $array, string
[`getFlatKeyNames(array<intstring, 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

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).

ParameterTypeDescription
$array`array<int“string, mixed>`
$prefix`string““null`

Returns array``<``int``|``string``, ``mixed``> — The flattened array.

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).

ParameterTypeDescription
$array`array<int“string, mixed>`
$prefix`string““null`

Returns array``<``int``, ``string``> — The flattened keys.

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.

ParameterTypeDescription
$pathstringThe path.

Returns array{parts: array<int, string>, absolute: bool} — The parts of the given path.

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.

ParameterTypeDescription
$partsArrayOrPathString`array<int, mixed>“string`
$array`array<int“string, mixed>`
$defaultmixedA default value if the path doesn’t exist in the array.

Returns mixed — The value stored at the given path.

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.

ParameterTypeDescription
$partsArrayOrPathString`array<int, mixed>“string`
$array`array<int“string, mixed>`

Returns bool — Whether the path exists in this array.

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.

ParameterTypeDescription
$partsArrayOrPathString`array<int, mixed>“string`
$array`array<int“string, mixed>`
$valuemixedThe value.

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.

ParameterTypeDescription
$partsArrayOrPathString`array<int, mixed>“string`
$array`array<int“string, mixed>`

Returns mixed — The previously stored value.