eventsauce/object-hydrator
Magic-less object hydration and serialization for PHP. Map arrays/decoded JSON to DTOs, commands, queries, and events by inspecting constructors and public getters—no private-property reflection. Supports custom keys, casting, and optional code generation for speed.
new Model($data) or libraries like spatie/array-to-object), saving dev time and reducing technical debt.Validator for pre-hydration checks.jenssegers/date, symfony/serializer) for high-throughput systems.symfony/serializer or google/protobuf.collect() or array_to_object() may suffice.spatie/laravel-array-to-object.For Executives: "This package lets us turn messy data (e.g., API responses, database records) into clean, validated objects with minimal code. It’s like a ‘smart factory’ for our domain models—reducing bugs, speeding up development, and aligning with our DDD architecture. Low risk (MIT license, 332+ stars), high reward for maintainability."
For Engineering:
new Model($data) or manual property assignment.$hydrator = new ObjectHydrator();
$event = $hydrator->hydrate(
UserRegistered::class,
['email' => 'user@example.com', 'timestamp' => '2023-01-01']
);
// $event is now a strict UserRegistered object with validated properties.
| Tool | Strengths | Weaknesses |
|---|---|---|
eventsauce/hydrator |
Strict typing, DDD-first | Less flexible for dynamic data |
symfony/serializer |
High performance, many formats | Overkill for simple object mapping |
| Manual hydration | Full control | Boilerplate, error-prone |
How can I help you explore Laravel packages today?