Main Classes Overview
Data Helpers provides several main classes for working with data:
DataAccessor
Section titled “DataAccessor”Read nested data with dot notation and wildcards. Analyze data structure with type information.
$accessor = new DataAccessor($data);
// Read values$email = $accessor->get('user.profile.email');$emails = $accessor->get('users.*.email');
// Type-safe collection getters$ages = $accessor->getIntCollection('users.*.age'); // DataCollection<int>
// Get structure with type information$structure = $accessor->getStructure();// ['name' => 'string', 'emails.*' => '\EmailDto', ...]DataCollection
Section titled “DataCollection”Framework-independent type-safe collection class with fluent API for working with arrays.
$collection = DataCollection::make([1, 2, 3, 4, 5]);
// Filter, map, reduce with method chaining$result = $collection ->filter(fn($item) => $item > 2) ->map(fn($item) => $item * 2) ->toArray(); // [6, 8, 10]
// Lazy evaluation for large datasetsforeach ($collection->lazyFilter(fn($item) => $item > 2) as $item) { // Process items one at a time}DataMutator
Section titled “DataMutator”Modify nested data structures safely.
$data = ['user' => ['name' => 'Jane']];DataMutator::make($data) ->set('user.name', 'John') ->merge('user.settings', ['theme' => 'dark']) ->unset('user.password');// $data is now modified in-placeDataMapper
Section titled “DataMapper”Transform data structures with templates and pipelines.
$source = ['profile' => ['name' => 'John', 'email' => 'john@example.com']];
$result = DataMapper::source($source) ->template([ 'user_name' => 'profile.name', 'user_email' => 'profile.email', ]) ->map();DataFilter
Section titled “DataFilter”Query and filter data with SQL-like API.
$data = [ ['category' => 'Electronics', 'price' => 150], ['category' => 'Electronics', 'price' => 50], ['category' => 'Books', 'price' => 200],];
$result = DataFilter::query($data) ->where('category', 'Electronics') ->where('price', '>', 100) ->orderBy('price', 'DESC') ->limit(10) ->get();SimpleDto
Section titled “SimpleDto”Immutable Data Transfer Objects with validation and casting.
class UserDto extends SimpleDto{ public string $name;
#[Email] public string $email;
#[Min(18)] public int $age;}
$user = UserDto::from(['name' => 'John', 'email' => 'john@example.com', 'age' => 25]);