Data Types Support
Data Helpers works with various data types and automatically detects the appropriate handling strategy.
Supported Types
Section titled “Supported Types”Arrays
Section titled “Arrays”Standard PHP arrays are fully supported:
$data = ['user' => ['name' => 'John']];$accessor = new DataAccessor($data);Objects
Section titled “Objects”Plain PHP objects with public properties:
$user = new stdClass();$user->name = 'John';$accessor = new DataAccessor($user);$name = $accessor->get('name');Laravel Collections
Section titled “Laravel Collections”Laravel Collections are automatically detected:
$collection = collect([ ['name' => 'Alice'], ['name' => 'Bob'],]);$accessor = new DataAccessor($collection);Eloquent Models
Section titled “Eloquent Models”Laravel Eloquent Models with relationships:
$user = User::with('profile')->first();$accessor = new DataAccessor($user);$email = $accessor->get('profile.email');Doctrine Collections
Section titled “Doctrine Collections”Doctrine Collections and Entities:
$users = $repository->findAll();$accessor = new DataAccessor($users);JSON Strings
Section titled “JSON Strings”JSON strings are automatically decoded:
$json = '{"user":{"name":"John"}}';$accessor = new DataAccessor($json);$name = $accessor->get('user.name');XML Strings
Section titled “XML Strings”XML strings are automatically converted:
$xml = '<user><name>John</name></user>';$accessor = new DataAccessor($xml);$name = $accessor->get('user.name');Type Detection
Section titled “Type Detection”Data Helpers automatically detects the data type and uses the appropriate strategy:
- JSON Detection - Checks for JSON string
- XML Detection - Checks for XML string
- Collection Detection - Checks for Laravel/Doctrine Collections
- Model Detection - Checks for Eloquent/Doctrine Models
- Object Detection - Handles plain objects
- Array Fallback - Default handling
Framework Detection
Section titled “Framework Detection”Framework support is automatically detected at runtime:
- Laravel - Detected via
class_exists(Collection::class) - Doctrine - Detected via
class_exists(DoctrineCollection::class) - Symfony - Detected via
class_exists(ArrayCollection::class)
No configuration needed!