Weave 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

Laminas Hydrator Laravel Package

laminas/laminas-hydrator

Laminas Hydrator converts arrays into objects and extracts objects back into arrays. It supports naming strategies, filters, hydration/extraction strategies, nested objects, and reusable data mapping for PHP applications.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Release Delta (4.19.0 → 5.0.0)

  • Baseline shift: The prior assessment was written against the 4.x line (latest 4.19.0). The project has now shipped 5.0.0, a major, backwards-incompatible release (2 issues / 20 PRs / 5 contributors). This is not a drop-in composer update; the version constraint, PHP floor, and any in-house extension points must be re-verified.
  • Most relevant changes for a Laravel consumer:
    1. Typed signatures everywhere (params, returns, properties) — PRs #135, #140, #141. Any custom StrategyInterface / HydratorInterface implementation in our codebase will fatal on signature mismatch.
    2. Integer filter-condition constants replaced by an enum — PR #162. Any FilterComposite::CONDITION_AND-style integer constants in form-request/allow-list code break.
    3. Static properties converted to instance properties in hydrators — PR #167. Behaviour change for anyone who configured a hydrator once and relied on that state leaking across instances.
    4. psr/container ^2.0 and laminas-servicemanager v4 support — PRs #132, #139. Better alignment with modern Laravel, but a hard conflict for apps still pinned to PSR-11 1.x.
    5. laminas-serializer v4 — PR #172. Affects SerializableStrategy only, but can conflict with other packages pinning serializer 3.x.
    6. Module Manager support and HydratorProviderInterface removed — PR #137. Effectively zero impact for Laravel; relevant only if we ever co-host Laminas MVC/Mezzio config.

Architecture Fit

  • Use Case Alignment: Unchanged. laminas-hydrator remains strongest at DTO mapping, declarative input filtering, and array↔object transformation — the awkward middle layer Laravel handles with ad-hoc ->only(), array_map, and fillable conventions.
  • Laravel Synergy: Still complementary, not competitive. It does not replace JsonResource, FormRequest, or fillable; it standardises the mapping logic those tools leave to us. 5.0.0's stricter typing is a net positive for static analysis (PHPStan/Psalm) in a Laravel codebase.
  • Domain-Specific Patterns (unchanged): API payload ↔ Eloquent/DTO bridges; allow-list extraction for form input; legacy array-config → OOP migration shims.
  • New consideration: the enum-based filter conditions make extraction rules more self-documenting and enum-safe — a modest win for reviewability and for preventing "magic integer" drift in a growing codebase.

Integration Feasibility

  • PHP/Laravel floor (must confirm before committing): The enum introduction implies PHP 8.1+. The prior assessment assumed PHP 7.2+/Laravel 8+. We should treat 5.0.0 as PHP 8.1+ only and verify against composer.json; this may drop Laravel 8 from the support matrix.
  • Container: psr/container ^2.0 support is an improvement for Laravel 10/11, where PSR-11 2.x is available. Apps still resolving to PSR-11 1.x via other dependencies will hit a Composer conflict rather than a runtime failure — cleaner failure mode, but a blocking one.
  • Migration Path: composer require laminas/laminas-hydrator:^5.0 plus the v4→v5 migration guide (PR #134, docs restructured in #170) is genuinely usable. The guide is the single biggest de-risking asset here — budget reading time for it explicitly rather than assuming.
  • Dependencies: Still optional-heavy. Core hydration stays self-contained; laminas-serializer v4 matters only if we adopt SerializableStrategy.
  • Blocker check: nothing in 5.0.0 conflicts structurally with Laravel's container, events, or Eloquent. The risk is version resolution, not design.

Technical Risk

  • Upgrade risk is concentrated in our own extension points, not the package: custom strategies and custom hydrators are the items most likely to break (typed signatures + filter enum). If we have none, the upgrade is largely mechanical. Action: inventory custom implementors of StrategyInterface, HydratorInterface, and AbstractHydrator first.
  • Silent behavioural change from static→instance properties: this is the subtlest item. Code that instantiated a hydrator, configured it, and assumed a later instance inherited configuration will now silently misbehave rather than fail loudly. Action: grep for hydrators configured outside the DI singleton registration.
  • Filter enum migration: mechanical but touches form/allow-list paths that are often security-adjacent (field allow-lists). Treat as a correctness change requiring test coverage, not a find-and-replace.
  • Learning curve (unchanged from prior assessment): strategy patterns and Laminas conventions still differ from Laravel idiom.
  • Performance (unchanged): reflection-based hydration remains slower than direct property access; benchmark against ->toArray() on hot API paths. 5.0.0 brings no performance regression signal, but no improvement either.
  • Ecosystem cadence risk: this is a second consecutive major (3.x → 4.x → 5.x) with heavy internal QA refactoring. That's healthy for the package and a recurring cost for us. Factor an upgrade line item into the annual roadmap rather than treating this as one-off.
  • Version-support risk: staying on 4.19.0 is viable short-term but leaves us on an unmaintained major. Set a decision date.

Key Questions

  1. PHP floor: Are all target applications on PHP 8.1+? If any Laravel 8 / PHP 7.4 service is in scope, 5.0.0 is out for that service and we run a split-version fleet.
  2. Custom extension points: How many in-house strategies/hydrators exist, and do they implement interfaces with 5.0.0's added types?
  3. Dependency resolution: Does anything in our graph pin psr/container ^1.x or laminas-serializer ^3.x?
  4. Static-state reliance: Is any hydrator configured outside the AppServiceProvider singleton binding?
  5. Upgrade vs. defer: Given 4.19.0 is the immediately preceding supported line, do we upgrade now (clean, one migration) or defer and pay a larger migration later?
  6. Scope discipline (carried forward): are we using hydrators for genuinely non-trivial mapping, or duplicating fill()/validated() for simple cases?

Integration Approach

Stack Fit

  • Service Container: Register hydrators as singletons in AppServiceProvider. In 5.0.0 this is now mandatory for shared configuration, since instance properties no longer leak across instances:
    $this->app->singleton(HydratorInterface::class, function ($app) {
        $hydrator = new ObjectPropertyHydrator();
        $hydrator->addFilter('allowList', new AllowListFilter(['id', 'name']), /* 5.x enum condition */);
        return $hydrator;
    });
    
  • API Layer: ArraySerializableHydrator for JsonResource payload shaping; unchanged in concept, typed signatures in 5.0.0 make the return contracts explicit.
  • Form Requests: Replace ->only()/->except() with FilterEnabledInterface + AllowListFilter. Update all filter-condition arguments to the new enum — this is the one code change every adopting team will hit.
  • Lumen / Livewire / Inertia: Unchanged; Lumen compatibility now depends on Lumen's PSR-11 version, which should be checked (Lumen trails Laravel on container majors).
  • Testing: HydratorAwareInterface doubles still work; mock expectations may need updated return types. Add a fixture test asserting filter-enum behaviour so the upgrade is provably behaviour-preserving.

Migration Path

  1. Inventory & pin (week 0): Lock 4.19.0 as the known-good baseline, enumerate every hydrator usage, custom strategy, and filter condition. Confirm PHP floor and PSR-11 resolution across all services.
  2. Read the v4→v5 migration guide (PR #134) before writing code. It exists specifically for this jump; skipping it is the most predictable way to burn the upgrade budget.
  3. Branch upgrade (1–2 weeks): Bump to ^5.0, convert filter constants to the enum, add parameter/return/property types to in-house strategies and hydrators, and re-run the test suite. Expect the failures to be concentrated and greppable.
  4. Validate behavioural parity: specifically for static→instance property changes — assert that configurations applied in one code path are not silently expected in another.
  5. Deprecation cleanup: where legacy mapping is wrapped rather than replaced, mark it and schedule removal in the same quarter.

Compatibility

  • Laravel 10/11: Expected full compatibility (PSR-11 2.x, PHP 8.1+). Confirm against composer.json.
  • Laravel 8/9: Likely blocked either by PHP floor or PSR-11 resolution — verify per service rather than assuming.
  • Doctrine / other mappers: unchanged guidance — don't stack hydrators on top of an ORM's own hydration inside the same path.
  • Coexistence: 5.x hydrators and native Laravel mapping can coexist; the upgrade does not force a codebase-wide rewrite.
  • Rollback: pinning back to 4.19.0 must remain possible until the enum/typing migration is fully merged on all services. Keep the branch isolated.

Sequencing

  1. Phase 0 — Feasibility (1 week): dependency resolution, PHP floor, extension-point inventory, migration-guide read. Output: go/no-go and per-service scope.
  2. Phase 1 — Core upgrade (1–2 weeks): bump constraint, enum migration, typed signatures on in-house code, ObjectPropertyHydrator/ArraySerializableHydrator verified on non-critical paths (admin panels, internal APIs).
  3. Phase 2 — Advanced features (1–2 weeks): AggregateHydrator for nested objects, custom strategies, SerializableStrategy only if serializer v4 is adoptable.
  4. Phase 3 — Optimisation & cadence (ongoing): benchmark hot paths, and add a standing line item for the next Laminas major.

Operational Impact

Maintenance

  • Pros: 5.0.0's typing and enums reduce the "magic value" surface in mapping code and make static analysis genuinely useful here. Centralised mapping logic remains easier to test than scattered array_map calls.
  • Cons: recurring major-upgrade cost. This is the second major since the assessment baseline, and each one requires touching our own extension points. That is a real, budgetable overhead — not a one-time integration cost.
  • Debugging: nested/aggregate hydrators still obscure stack traces; the event-manager hook remains the observability answer, and should be wired before advanced hydrators go live.
  • Ownership: assign a named owner for the hydrator dependency so the next major doesn't surface as a surprise during an unrelated sprint.

Support

  • Upstream: documentation was explicitly restructured for v5 (PR #170) and a v4→v5 migration guide was authored (PR #134) — a strong support signal for a community package. Contributors remain small (5 on this release), so response times on novel issues should not be assumed.
  • Internal: document the singleton hydrator registrations, the filter enum choices, and the reasoning for any custom strategy. These are the artefacts that make the next major cheap.
  • Decision record: capture explicitly why 5.0.0 was adopted now (or deferred) and against which PHP/Laravel floor — future readers will need the constraint context.

Scaling

  • Throughput: reflection-based hydration is unchanged in cost; on high-QPS endpoints, still benchmark against native ->toArray(). Don't route every response through a hydrator by default.
  • Statefulness: converting static to instance properties removes an unbounded shared-state hazard but also means configuration must be deliberate. Singleton registration keeps configuration cost paid once at boot, which scales fine; per-request hydrator construction with filters attached each time does not — avoid it.
  • Memory: deeply nested aggregate hydration remains the ceiling; lazy loading and explicit depth limits still apply.

Failure Modes

  • Typed-signature fatals in in-house strategies — highest likelihood, caught at deploy by any test touching that path. Mitigate with a full-suite run before merge, not after.
  • Filter-enum mis-migration — highest severity, because a wrong condition can widen or narrow field allow-lists silently. Requires targeted tests on every extraction path that handles user input.
  • Composer resolution failure on PSR-11 / serializer — low severity, fails fast at install, but blocks an entire release train if discovered mid-sprint.
  • Silent configuration leakage loss (static→instance) — low likelihood if we register singletons, high confusion if we don't, because the symptom is "field quietly not mapped" rather than an exception.
  • Rollback: clean, since the upgrade can be branch-isolated and reverted with the version pin. Preserve that property.

Ramp-Up

  • Engineering: 1–2 weeks for a team already familiar with hydrators; 3–4 weeks if the team is new to Laminas conventions and carries custom strategies. The migration guide shortens the former considerably.
  • TPM overhead: ~1 week of feasibility work (dependency audit, PHP floor confirmation, extension-point inventory) before any commitment to a delivery date.
  • Recommendation: update the assessment and proceed with a scoped 5.0.0 upgrade, gated on the Phase 0 feasibility output. Do not authorise a date until the PSR-11/PHP-floor check and the custom-strategy inventory are complete — those two answers determine whether this is a two-week mechanical bump or a multi-service migration.
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.
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core