Skip to content

DataAccessor API

Complete API reference for DataAccessor.

Create a new DataAccessor instance.

$accessor = new DataAccessor($data);

Create a new instance (fluent).

$accessor = DataAccessor::make($data);

get(string $path, mixed $default = null): mixed

Section titled “get(string $path, mixed $default = null): mixed”

Get value at path.

$value = $accessor->get('user.name');
$value = $accessor->get('user.age', 0);

getString(string $path, string $default = ''): string

Section titled “getString(string $path, string $default = ''): string”

Get string value.

$name = $accessor->getString('user.name');

getInt(string $path, int $default = 0): int

Section titled “getInt(string $path, int $default = 0): int”

Get integer value.

$age = $accessor->getInt('user.age');

getFloat(string $path, float $default = 0.0): float

Section titled “getFloat(string $path, float $default = 0.0): float”

Get float value.

$price = $accessor->getFloat('product.price');

getBool(string $path, bool $default = false): bool

Section titled “getBool(string $path, bool $default = false): bool”

Get boolean value.

$active = $accessor->getBool('user.active');

getArray(string $path, array $default = []): array

Section titled “getArray(string $path, array $default = []): array”

Get array value.

$tags = $accessor->getArray('post.tags');

Check if path exists.

if ($accessor->has('user.email')) {
// ...
}

Check if any path exists.

if ($accessor->hasAny(['user.email', 'user.phone'])) {
// ...
}

Check if all paths exist.

if ($accessor->hasAll(['user.name', 'user.email'])) {
// ...
}

Get values matching wildcard pattern.

$names = $accessor->getWildcard('users.*.name');

Get underlying array.

$data = $accessor->toArray();

Get all keys.

$keys = $accessor->keys();

Get all values.

$values = $accessor->values();

Get data structure with type information as flat array with dot-notation.

Returns an array where keys are dot-notation paths (with wildcards for arrays) and values are type strings (with union types for mixed values).

Return Format:

  • Primitive types: 'string', 'int', 'float', 'bool', 'null'
  • Arrays: 'array'
  • Objects: Full namespace with leading backslash (e.g., '\EmailDTO')
  • Union types: Pipe-separated, alphabetically sorted (e.g., 'bool|int|null|string')
  • Array elements: Wildcard notation (e.g., 'emails.*')
$structure = $accessor->getStructure();
// Example output:
// [
// 'name' => 'string',
// 'age' => 'int',
// 'emails' => 'array',
// 'emails.*' => '\EmailDTO',
// 'emails.*.email' => 'string',
// 'emails.*.verified' => 'bool',
// ]

Get data structure with type information as multidimensional array.

Returns a nested array structure where leaf values are type strings (with union types for mixed values). Arrays use wildcards.

Return Format:

  • Same type format as getStructure()
  • Nested structure instead of flat dot-notation
  • Array elements use '*' key
$structure = $accessor->getStructureMultidimensional();
// Example output:
// [
// 'name' => 'string',
// 'age' => 'int',
// 'emails' => [
// '*' => [
// 'email' => 'string',
// 'verified' => 'bool',
// ],
// ],
// ]