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

Laminas Hydrator Laravel Package

laminas/laminas-hydrator

Laminas Hydrator provides flexible strategies to hydrate and extract data between objects and arrays. Supports reflection, class methods, naming strategies, and custom hydrators, making it easy to map entities, DTOs, and forms cleanly across your application.

View on GitHub
Deep Wiki
Context7

Naming Strategies

Sometimes, the representation of a property should not share the same name as the property itself. As an example, when serializing an object for a JSON payload, you may want to convert camelCase properties to underscore_separated properties, and vice versa when deserializing JSON to an object.

To make that possible, laminas-hydrator provides naming strategies. These are similar to strategies, but instead of operating on the value, they operate on the name.

NamingStrategyInterface

Naming strategies implement Laminas\Hydrator\NamingStrategy\NamingStrategyInterface:

namespace Laminas\Hydrator\NamingStrategy;

/**
 * Allow property extraction / hydration for hydrator
 */
interface NamingStrategyInterface
{
    /**
     * Converts the given name so that it can be extracted by the hydrator.
     *
     * [@param](https://github.com/param) null|mixed[] $data The original data for context.
     */
    public function hydrate(string $name, ?array $data = null) : string;

    /**
     * Converts the given name so that it can be hydrated by the hydrator.
     *
     * [@param](https://github.com/param) null|object $object The original object for context.
     */
    public function extract(string $name, ?object $object = null) : string;
}

Providing naming strategies

Hydrators can indicate they will consume naming strategies, as well as allow registration of them, by implementing Laminas\Hydrator\NamingStrategy\NamingStrategyEnabledInterface:

namespace Laminas\Hydrator\NamingStrategy;

interface NamingStrategyEnabledInterface
{
    /**
     * Sets the naming strategy.
     */
    public function setNamingStrategy(NamingStrategyInterface $strategy) : void;

    /**
     * Gets the naming strategy.
     */
    public function getNamingStrategy() : NamingStrategyInterface;

    /**
     * Checks if a naming strategy exists.
     */
    public function hasNamingStrategy() : bool;

    /**
     * Removes the naming strategy.
     */
    public function removeNamingStrategy() : void;
}

We provide a default implementation of this interface within the Laminas\Hydrator\AbstractHydrator definition. Its getNamingStrategy() will lazy-load an IdentityNamingStrategy if none has been previously registered. Since all shipped hydrators extend AbstractHydrator, they can consume naming strategies.

Shipped naming strategies

We provide the following naming strategies:

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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle