Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Object Hydrator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Domain-Driven Design (DDD) Alignment: Enables strict object hydration for domain models, enforcing business rules and type safety in event-driven architectures (e.g., CQRS, Event Sourcing).
  • API/Service Layer Abstraction: Simplifies transformation of raw data (e.g., JSON, DB records) into strongly-typed objects, reducing boilerplate in controllers/services.
  • Build vs. Buy: Avoids reinventing hydration logic (e.g., manual new Model($data) or libraries like spatie/array-to-object), saving dev time and reducing technical debt.
  • Use Cases:
    • Event Sourcing: Hydrate domain events from storage (e.g., Doctrine, Redis).
    • API Integration: Convert API responses (e.g., Stripe, Shopify) into typed objects.
    • CLI/Jobs: Parse structured input (e.g., CSV, config files) into domain objects.
  • Roadmap Enabler: Supports future features like:
    • Validation: Integrate with Laravel’s Validator for pre-hydration checks.
    • Performance: Benchmark against alternatives (e.g., jenssegers/date, symfony/serializer) for high-throughput systems.

When to Consider This Package

  • Adopt if:
    • Your system relies on strict object modeling (e.g., DDD, Event Sourcing) where raw data must map to immutable/validated objects.
    • You need type safety without sacrificing flexibility (e.g., nested objects, custom hydration logic).
    • Your team prioritizes maintainability over micro-optimizations (MIT license, active community).
  • Look elsewhere if:
    • You require high-performance serialization (e.g., gRPC, protobufs) → Use symfony/serializer or google/protobuf.
    • Your use case is simple key-value mapping → Laravel’s native collect() or array_to_object() may suffice.
    • You need dynamic property hydration (e.g., JSON:API) → Consider spatie/laravel-array-to-object.
    • Your stack is non-PHP (e.g., Node.js, Python) → Use language-specific tools.

How to Pitch It (Stakeholders)

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:

  • Pros:
    • DRY: Eliminates repetitive new Model($data) or manual property assignment.
    • Extensible: Supports custom hydrators for complex logic (e.g., date parsing, nested objects).
    • Laravel-Friendly: Works seamlessly with Eloquent, API resources, and service containers.
  • Example Use Case:
    $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.
    
  • Migration Path:
    • Start with critical paths (e.g., event hydration).
    • Gradually replace manual hydration in controllers/services.
  • Alternatives Compared:
    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
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport