PHPackages                             xactsystems/type-hint-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. [Database &amp; ORM](/categories/database)
4. /
5. xactsystems/type-hint-hydrator

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

xactsystems/type-hint-hydrator
==============================

A Symfony object hydrator based on declared types and annotation type-hints.

v5.0.5(3d ago)0969[6 issues](https://github.com/XactSystems/type-hint-hydrator/issues)MITPHPPHP &gt;=8.1

Since Nov 1Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/XactSystems/type-hint-hydrator)[ Packagist](https://packagist.org/packages/xactsystems/type-hint-hydrator)[ RSS](/packages/xactsystems-type-hint-hydrator/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (34)Versions (53)Used By (0)

type-hint-hydrator
==================

[](#type-hint-hydrator)

A Symfony Type Hint hydrator that uses declared types and @var annotations to determine the hydrated type. Under the hood it uses the laminas-hydrator for the mapping process. See

It can handle request objects and arrays of data to hydrate annotated classes and arrays etc. It can also validate against any Assert annotations the hydrated object may contain.

If properties of the hydrated object are annotated as Doctrine Entities, the hydrator will attempt to load the entity for the key value provided. We currently don't support composite keys.

Documentation
-------------

[](#documentation)

---

### 1) Add the type-hint-hydrator to your project

[](#1-add-the-type-hint-hydrator-to-your-project)

```
composer require xactsystems/type-hint-hydrator
```

### 2) Add the bundle to your configuration file

[](#2-add-the-bundle-to-your-configuration-file)

If you are using Symfony 4 onwards and using Flex you can skip this step.

Symfony 4.4 onwards - bundles.php

```
    return [
        ...
        Xact\TypeHintHydrator\XactTypeHintHydrator::class => ['all' => true],
    ];
```

### 3) Declare types or annotate your hydrated object properties

[](#3-declare-types-or-annotate-your-hydrated-object-properties)

```
namespace App;

class Author
{
    /**
     * @var int|null
     */
    public $objectId;

    public int $noneNullId;

    /**
     * @var string|null
     */
    public $fullName;

    public float $myFloat;

    /**
     * @var \App\Book[]
     */
    public $books;

    /**
     * @var \App\Authors[]
     */
    public array $authors;

    /**
     * @var array
     */
    public array $references;
}
```

### 4) Hydrate your object in your controller

[](#4-hydrate-your-object-in-your-controller)

```
    use Xact\TypeHintHydrator\TypeHintHydrator;
    ...
    public function update(Request $request, EntityManagerInterface $em, TypeHintHydrator $hydrator): JsonResponse
    {
        $author = new Author();
        $hydrator->handleRequest($request, $author);
        if (!$hydrator->isValid()) {
            return JsonResponse::fromJsonString($hydrator->getJsonErrors(), JsonResponse::HTTP_BAD_REQUEST);
        }

        $em->persist($author);
        $em->flush();

        return new JsonResponse::fromJsonString(json_encode($author));
    }
```

Or to update and existing entity:

```
    use Xact\TypeHintHydrator\TypeHintHydrator;
    ...
    /**
     * @Route("/author/{id}", methods={"POST"})
     * @ParamConverter("author", class="App\Entity\Author")
     */
    public function update(Author $author, Request $request, TypeHintHydrator $hydrator): Response
    {
        $hydrator->handleRequest($request, $author);
        if (!$hydrator->isValid()) {
            return JsonResponse::fromJsonString($hydrator->getJsonErrors(), JsonResponse::HTTP_BAD_REQUEST);
        }

        $em->persist($author);
        $em->flush();

        return new JsonResponse::fromJsonString(json_encode($author));
    }
```

### 5) Smile and be happy

[](#5-smile-and-be-happy)

It really is that easy. No more form types! Annotate your objects correctly with types and assertions, make sure your submitted forms use the same names as your object proprieties and it will just work!

Create proper Model classes for your data and hydrate them, and let them do the work a proper MVC model should.

Methods
-------

[](#methods)

### hydrateObject

[](#hydrateobject)

```
hydrateObject(array $values, object $target, bool $validate = true, $constraints = null, $groups = null): object
```

Hydrate an object from an array of values. If $validate is true, the hydrated object is validated against annotations and supplied validation constraints and groups.

### handleRequest

[](#handlerequest)

```
handleRequest(Request $request, object $target, bool $validate = true, $constraints = null, $groups = null): object
```

Hydrate an object from the Request object. Property mapping is based on the submitted form property names matching the property names of the hydrated object. If $validate is true, the hydrated object is validated against annotations and supplied validation constraints and groups.

### isValid

[](#isvalid)

```
isValid()
```

Is the hydrated object valid after processing the validation constraints. If no validation has occurred the method returns true;

### getErrors

[](#geterrors)

```
getErrors()
```

Return a Symfony\\Component\\Validator\\ConstraintViolationListInterface list of any validation errors.

### getJsonErrors

[](#getjsonerrors)

```
getJsonErrors()
```

Return a JSON serialised version of getErrors().

Credits
-------

[](#credits)

---

- Ian Foulds as the creator of this package.
- Marco Pivetta () for developing and maintaining the laminas-hydrator - .

License
-------

[](#license)

---

This bundle is released under the MIT license. See the complete license in the bundle:

[LICENSE](https://github.com/xactsystems/type-hint-hydrator/blob/master/LICENSE)

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance54

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~32 days

Recently: every ~86 days

Total

52

Last Release

3d ago

Major Versions

3.4.8 → 4.4.32023-03-02

3.4.10 → 4.5.02023-06-13

4.x-dev → v5.0.02024-08-28

v3.4.17 → v5.0.32025-05-07

v3.4.19 → v5.0.42025-06-03

PHP version history (4 changes)1.0.0PHP ^7.3

2.0.0PHP &gt;=7.4

v5.0.0PHP &gt;=8.1

v3.4.14PHP ^7.4

### Community

Maintainers

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

---

Top Contributors

[![ianef](https://avatars.githubusercontent.com/u/5128087?v=4)](https://github.com/ianef "ianef (35 commits)")

---

Tags

requestsymfonyarraydoctrineobjectentityhydratorannotationtyped properties

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xactsystems-type-hint-hydrator/health.svg)

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

###  Alternatives

[fresh/doctrine-enum-bundle

Provides support of ENUM type for Doctrine2 in Symfony applications.

4636.8M12](/packages/fresh-doctrine-enum-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[api-platform/schema-generator

Various tools to generate a data model based on Schema.org vocables

4714.2M7](/packages/api-platform-schema-generator)[pmill/doctrine-array-hydrator

 An array to entity hydrator for Doctrine 2 entities

36482.9k3](/packages/pmill-doctrine-array-hydrator)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1022.4k](/packages/rcsofttech-audit-trail-bundle)[indaxia/doctrine-orm-transformations

Provides JSON-ready Doctrine ORM Entity-Array transfomtaions

1296.4k](/packages/indaxia-doctrine-orm-transformations)

PHPackages © 2026

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