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 tools to hydrate and extract data between arrays and objects. Includes hydrator strategies, naming conventions, and integration helpers for forms and domain models, supporting multiple hydrator implementations and extensions.

View on GitHub
Deep Wiki
Context7

laminas-hydrator

Hydration is the act of populating an object from a set of data.

laminas-hydrator is a simple component to provide mechanisms both for hydrating objects, as well as extracting data sets from them.

The component consists of interfaces, and several implementations for common use cases.

Base Interfaces

ExtractionInterface

namespace Laminas\Hydrator;

interface ExtractionInterface
{
    /
     * Extract values from an object
     *
     * [@param](https://github.com/param)  object $object
     * [@return](https://github.com/return) array
     */
    public function extract($object);
}

HydrationInterface

namespace Laminas\Hydrator;

interface HydrationInterface
{
    /
     * Hydrate $object with the provided $data.
     *
     * [@param](https://github.com/param)  array $data
     * [@param](https://github.com/param)  object $object
     * [@return](https://github.com/return) object
     */
    public function hydrate(array $data, $object);
}

HydratorInterface

namespace Laminas\Hydrator;

interface HydratorInterface extends
    ExtractionInterface,
    HydrationInterface
{
}

Usage

Usage involves instantiating the hydrator, and then passing information to it.

use Laminas\Hydrator;
$hydrator = new Hydrator\ArraySerializable();

// To hydrate an object from values in an array:
$object = $hydrator->hydrate($data, new ArrayObject());

// or, going the other way and extracting the values from an object as an array:
$data = $hydrator->extract($object);

Available Implementations

Laminas\Hydrator\ArraySerializable

Follows the definition of ArrayObject. Objects must implement either the exchangeArray() or populate() methods to support hydration, and the getArrayCopy() method to support extraction.

Laminas\Hydrator\ClassMethods

Any data key matching a setter method will be called in order to hydrate; any method matching a getter method will be called for extraction.

Laminas\Hydrator\DelegatingHydrator

Composes a hydrator locator, and will delegate hydrate() and extract() calls to the appropriate one based upon the class name of the object being operated on.

// Instantiate each hydrator you wish to delegate to
$albumHydrator = new Laminas\Hydrator\ClassMethods;
$artistHydrator = new Laminas\Hydrator\ClassMethods;

// Map the entity class name to the hydrator using the HydratorPluginManager.
// In this case we have two entity classes, "Album" and "Artist".
$hydrators = new Laminas\Hydrator\HydratorPluginManager;
$hydrators->setService('Album', $albumHydrator);
$hydrators->setService('Artist', $artistHydrator);

// Create the DelegatingHydrator and tell it to use our configured hydrator locator
$delegating = new Laminas\Hydrator\DelegatingHydrator($hydrators);

// Now we can use $delegating to hydrate or extract any supported object
$array = $delegating->extract(new Artist);
$artist = $delegating->hydrate($data, new Artist);

Laminas\Hydrator\ObjectProperty

Any data key matching a publicly accessible property will be hydrated; any public properties will be used for extraction.

Laminas\Hydrator\Reflection

Similar to the ObjectProperty hydrator, but uses PHP's reflection API to hydrate or extract properties of any visibility. Any data key matching an existing property will be hydrated; any existing properties will be used for extraction.

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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi