Skip to content

Introduction

Data Helpers is a powerful, framework-agnostic PHP library for accessing, transforming, and mapping complex nested data structures with ease. It provides dot notation access, wildcard support, data mapping with templates, caching, and 40+ built-in filters.

Data Helpers is a comprehensive toolkit for working with data in PHP applications. It provides five main components:

  • DataAccessor - Read nested data with dot notation and wildcards
  • DataMutator - Modify nested data structures safely
  • DataMapper - Transform data structures with templates and pipelines
  • DataFilter - Query and filter data with SQL-like API
  • SimpleDTO - Immutable Data Transfer Objects with validation and casting
// From this messy API response...
$apiResponse = [
'data' => [
'departments' => [
['users' => [['email' => 'alice@example.com'], ['email' => 'bob@example.com']]],
['users' => [['email' => 'charlie@example.com']]],
],
],
];
// ...to this clean result in one line
$accessor = new DataAccessor($apiResponse);
$emails = $accessor->get('data.departments.*.users.*.email');
// Result: ['alice@example.com', 'bob@example.com', 'charlie@example.com']

Without Data Helpers, you need to write verbose code with multiple loops and null checks:

// Without Data Helpers
$emails = [];
foreach ($data['departments'] ?? [] as $dept) {
foreach ($dept['users'] ?? [] as $user) {
if (isset($user['email'])) {
$emails[] = $user['email'];
}
}
}
// With Data Helpers
$emails = $accessor->get('departments.*.users.*.email');

Map between different data formats, APIs, or database schemas without writing repetitive transformation code:

$mapper = new DataMapper();
$result = $mapper->map($source, [
'user_name' => '{{ profile.name }}',
'user_email' => '{{ profile.contact.email }}',
'total_orders' => '{{ orders.*.amount | sum }}',
]);
  • PHPStan Level 9 compliant
  • 2900+ tests with comprehensive coverage
  • Works reliably with arrays, objects, Collections, Models, JSON, and XML

Use it anywhere - Laravel, Symfony, Doctrine, or plain PHP. Framework support is automatically detected at runtime:

  • Laravel 9+ - Collections, Eloquent Models
  • Symfony 6+ - Collections, Entities
  • Doctrine 2+ - Collections, Entities
  • Plain PHP - Works out of the box

DataMapper is significantly faster than traditional serializers for DTO mapping:

  • Up to 3.7x faster than Symfony Serializer
  • Optimized for nested data structures
  • Zero reflection overhead for template-based mapping
  • See Performance Benchmarks for detailed comparison
  • Dot notation path access
  • Wildcard support for nested arrays
  • Type-safe getters
  • Collections support (Laravel/Doctrine)
  • JSON and XML support
  • Safe nested value setting
  • Merge operations
  • Unset operations
  • Wildcard mutations
  • Template-based mapping
  • Pipeline filters (40+ built-in)
  • Reverse mapping
  • Query builder
  • GROUP BY and aggregations
  • Custom operators
  • SQL-like query API
  • WHERE, ORDER BY, LIMIT, OFFSET
  • Custom operators
  • Chainable methods
  • Immutable DTOs
  • 20+ built-in casts
  • Validation system (22+ attributes)
  • Property mapping
  • Conditional properties (18 attributes)
  • Lazy properties
  • Computed properties
  • Collections support
  • TypeScript generation
  • Framework integration
  • PHP 8.2 or higher
  • No required dependencies
  • Optional framework integrations:
    • Laravel 9+
    • Symfony 6+
    • Doctrine 2+

Install via Composer:

Terminal window
composer require event4u/data-helpers

See Installation for detailed setup instructions.

Data Helpers offers several advantages over comparable projects:

  • Framework-agnostic - Works with Laravel, Symfony, or plain PHP
  • Zero dependencies - No required dependencies, optional framework integrations
  • Comprehensive - 5 main components covering all data manipulation needs
  • Well-tested - 2900+ tests with PHPStan Level 9 compliance
  • High performance - Up to 3.7x faster than traditional serializers
  • Rich feature set - 40+ filters, 20+ casts, 22+ validation attributes, 18 conditional attributes

See Performance Comparison for detailed benchmarks.

Data Helpers is open-source software licensed under the MIT license.