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(1mo ago)0969[6 issues](https://github.com/XactSystems/type-hint-hydrator/issues)MITPHPPHP &gt;=8.1

Since Nov 1Pushed 1mo 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 3w ago

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

49

—

FairBetter than 94% of packages

Maintenance89

Actively maintained with recent releases

Popularity14

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

58d 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://avatars.githubusercontent.com/u/5128087?v=4)[Ian Foulds](/maintainers/ianef)[@ianef](https://github.com/ianef)

---

Top Contributors

[![ianef](https://avatars.githubusercontent.com/u/5128087?v=4)](https://github.com/ianef "ianef (36 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

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[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.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[sulu/sulu

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

1.3k1.4M203](/packages/sulu-sulu)[kimai/kimai

Kimai - Time Tracking

4.8k9.0k1](/packages/kimai-kimai)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M338](/packages/api-platform-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)

PHPackages © 2026

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