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.
composer update; the version constraint, PHP floor, and any in-house extension points must be re-verified.StrategyInterface / HydratorInterface implementation in our codebase will fatal on signature mismatch.FilterComposite::CONDITION_AND-style integer constants in form-request/allow-list code break.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.laminas-serializer v4 — PR #172. Affects SerializableStrategy only, but can conflict with other packages pinning serializer 3.x.HydratorProviderInterface removed — PR #137. Effectively zero impact for Laravel; relevant only if we ever co-host Laminas MVC/Mezzio config.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.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.composer.json; this may drop Laravel 8 from the support matrix.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.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.laminas-serializer v4 matters only if we adopt SerializableStrategy.StrategyInterface, HydratorInterface, and AbstractHydrator first.->toArray() on hot API paths. 5.0.0 brings no performance regression signal, but no improvement either.psr/container ^1.x or laminas-serializer ^3.x?AppServiceProvider singleton binding?fill()/validated() for simple cases?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;
});
ArraySerializableHydrator for JsonResource payload shaping; unchanged in concept, typed signatures in 5.0.0 make the return contracts explicit.->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.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.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.^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.composer.json.4.19.0 must remain possible until the enum/typing migration is fully merged on all services. Keep the branch isolated.ObjectPropertyHydrator/ArraySerializableHydrator verified on non-critical paths (admin panels, internal APIs).AggregateHydrator for nested objects, custom strategies, SerializableStrategy only if serializer v4 is adoptable.array_map calls.->toArray(). Don't route every response through a hydrator by default.How can I help you explore Laravel packages today?