DataAccessor API
Complete API reference for DataAccessor.
Constructor
Section titled “Constructor”__construct(array $data)
Section titled “__construct(array $data)”Create a new DataAccessor instance.
$accessor = new DataAccessor($data);Static Methods
Section titled “Static Methods”make(array $data): self
Section titled “make(array $data): self”Create a new instance (fluent).
$accessor = DataAccessor::make($data);Get Methods
Section titled “Get Methods”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');Has Methods
Section titled “Has Methods”has(string $path): bool
Section titled “has(string $path): bool”Check if path exists.
if ($accessor->has('user.email')) { // ...}hasAny(array $paths): bool
Section titled “hasAny(array $paths): bool”Check if any path exists.
if ($accessor->hasAny(['user.email', 'user.phone'])) { // ...}hasAll(array $paths): bool
Section titled “hasAll(array $paths): bool”Check if all paths exist.
if ($accessor->hasAll(['user.name', 'user.email'])) { // ...}Wildcard Methods
Section titled “Wildcard Methods”getWildcard(string $pattern): array
Section titled “getWildcard(string $pattern): array”Get values matching wildcard pattern.
$names = $accessor->getWildcard('users.*.name');Array Methods
Section titled “Array Methods”toArray(): array
Section titled “toArray(): array”Get underlying array.
$data = $accessor->toArray();keys(): array
Section titled “keys(): array”Get all keys.
$keys = $accessor->keys();values(): array
Section titled “values(): array”Get all values.
$values = $accessor->values();Structure Introspection Methods
Section titled “Structure Introspection Methods”getStructure(): array
Section titled “getStructure(): array”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',// ]getStructureMultidimensional(): array
Section titled “getStructureMultidimensional(): array”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',// ],// ],// ]See Also
Section titled “See Also”- DataAccessor Guide - Complete guide
- Dot-Notation - Path syntax
- Wildcards - Wildcard patterns