PHPackages                             atto/hydrator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. atto/hydrator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

atto/hydrator
=============

description

0.1.2(5mo ago)13011[8 issues](https://github.com/atto-php/hydrator/issues)proprietaryPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0CI passing

Since Dec 29Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/atto-php/hydrator)[ Packagist](https://packagist.org/packages/atto/hydrator)[ RSS](/packages/atto-hydrator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (5)Used By (0)

Atto Hydrator
=============

[](#atto-hydrator)

The hydrator is designed to *quickly* serialise (extract) and deserialise (hydrate) complex objects.

It works out of the box on simple data structures. For anything else, [behaviour can be defined](#manually-defined-behaviour) to meet your needs.

Default Behaviour
-----------------

[](#default-behaviour)

Your DTO's properties are extracted into an array.

The value of each property is converted into a JSON string.

Arrays must [specify a subtype](#subtype). Arrays ordered integer keys (lists) are extracted into a *nested* JSON array. Arrays with specified keys are extracted into a *nested* JSON object.

Object are extracted into a *nested* JSON object.

If the default behaviour does not suit your needs; you can [manually define alternate behaviour](#manually-defined-behaviour)

Manually Defined Behaviour
--------------------------

[](#manually-defined-behaviour)

Behaviour can be defined using *attributes* from the `Atto\Hydrator\Attribute` namespace.

### Serialization Strategy

[](#serialization-strategy)

Serialization strategies are only useful for arrays of data. They will have no impact on scalars. They cannot be used on objects.

The default strategy is to serialize as JSON.

```
    // This is the default behaviour if omitted.
    #[SerializationStrategy(SerializationStrategyType::JSON)]
    private array $myList;
```

It may also be serialized to a comma-delimited or pipe-delimited list.

```
    #[SerializationStrategy(SerializationStrategyType::CommaDelimited)]
    private array $myCommaDelimitedList;
    #[SerializationStrategy(SerializationStrategyType::PipeDelimited)]
    private array $myPipeDelimitedList;
```

CommaDelimited and PipeDelimited serialisation will:

- Only work for lists of simple data.
- Will lose your array keys.

### Hydration Strategy

[](#hydration-strategy)

#### Json

[](#json)

Json will json encode your property before the entire object is json encoded.

```
class MyObject
{
    #[HydrationStrategy(HydrationStrategyType::Json)]
    private MyNestedObject $myNestedObject;
}

class MyNestedObject
{
    private int $myInt = 1;
}
```

The hydrator will extract the following output:

```
['myNestedObject' => '{"myInt":1}']
```

#### Merge

[](#merge)

Merge can only be used for a single level.

If you specify Merge on an object contains a nested object property. The nested object's properties are merged into the original object, as if it were its own properties.

```
class MyObject
{
    #[HydrationStrategy(HydrationStrategyType::Merge)]
    private MyNestedObject $myNestedObject;
}

class MyNestedObject
{
    private int $myInt = 1;
}
```

The hydrator will extract the following output:

```
    ['myNestedObject_myInt' => 1]
```

If your property names include underscores, undefined behaviour MAY occur. Stick to *camelCase* property names for predictable behaviour.

#### Nest

[](#nest)

Nest is the default behaviour of any property [except DateTimes, Enums and Scalars](#datetime-enum--scalar).

You should never need to specify it explicitly.

```
class MyObject
{
    #[HydrationStrategy(HydrationStrategyType::Nest)]
    private MyNestedObject $myNestedObject;
}

class MyNestedObject
{
    private int $myInt = 1;
}
```

The hydrator will extract the following output:

```
    [
        'myNestedObject' => ['myInt' => 1],
    ]
```

#### Passthrough

[](#passthrough)

Passthrough will leave your property pass through untouched.

If Passthrough is used, it should be used at every level above it as well.

#### StringWrapper

[](#stringwrapper)

A StringWrapper is an object which; takes a single string argument to `__construct` and returns it with `__toString()`.

i.e.

```
class MyStringWrapper
{
    public function __construct(
        private string $myString = 'Hello, World!',
    ) {
    }

    public function __toString()
    {
        return $this->myString;
    }
}
```

For objects like this, we can serialise them as their constructor argument, a simple string.

```
"Hello, World!"
```

#### DateTime, Enum &amp; Scalar

[](#datetime-enum--scalar)

Datetimes, Enums and Scalars have their own default strategies.

They do not need to be specified, but they can be overriden if you choose.

### Subtype

[](#subtype)

For an array, a subtype must be specified.

```
    #[Subtype(\DateTime::class)]
    private array $listOfDateTimes
```

**Arrays must only contain items of that subtype**.

This is because, serialised data does not contain information of its type. The hydrator uses this `Subtype` attribute to determine what to hydrate each item as.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance50

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~149 days

Total

3

Last Release

175d ago

PHP version history (2 changes)0.1.0PHP ~8.2.0 || ~8.3.0

0.1.2PHP ~8.2.0 || ~8.3.0 || ~8.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/aee2ff8ab8a5dc8e25d2d59d9402f0395ab411fa46d99c25991857bcafba0639?d=identicon)[carnage](/maintainers/carnage)

---

Top Contributors

[![charjr](https://avatars.githubusercontent.com/u/102669158?v=4)](https://github.com/charjr "charjr (42 commits)")[![carnage](https://avatars.githubusercontent.com/u/846596?v=4)](https://github.com/carnage "carnage (27 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/atto-hydrator/health.svg)

```
[![Health](https://phpackages.com/badges/atto-hydrator/health.svg)](https://phpackages.com/packages/atto-hydrator)
```

###  Alternatives

[roave/backward-compatibility-check

Tool to compare two revisions of a public API to check for BC breaks

5953.3M56](/packages/roave-backward-compatibility-check)[php-soap/wsdl

Deals with WSDLs

173.5M12](/packages/php-soap-wsdl)[phel-lang/phel-lang

Phel is a functional programming language that compiles to PHP

4743.5k10](/packages/phel-lang-phel-lang)[symfony/ai-bundle

Integration bundle for Symfony AI components

30282.3k6](/packages/symfony-ai-bundle)[bartlett/umlwriter

Create UML class diagrams from your PHP source.

6313.0k1](/packages/bartlett-umlwriter)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
