PHPackages                             thomasvargiu/laminas-doctrine-hydration-module - 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. thomasvargiu/laminas-doctrine-hydration-module

ActiveLibrary[Database &amp; ORM](/categories/database)

thomasvargiu/laminas-doctrine-hydration-module
==============================================

Doctrine hydrators for Laminas Framework

5.2.0(1y ago)04MITPHPPHP ^7.4 || ^8.0

Since May 22Pushed 1y agoCompare

[ Source](https://github.com/thomasvargiu/zf-doctrine-hydration-module)[ Packagist](https://packagist.org/packages/thomasvargiu/laminas-doctrine-hydration-module)[ RSS](/packages/thomasvargiu-laminas-doctrine-hydration-module/feed)WikiDiscussions 5.0.x Synced 1mo ago

READMEChangelogDependencies (12)Versions (20)Used By (0)

> ## Repository abandoned
>
> [](#repository-abandoned)
>
> This repo has been updated to support PHP 7.4 and 8+ as well as converted to use Laminas packages. These upgrades where done to address a dependency with an upstream package.
>
> Feel free to use it AS-IS, we won't be providing any support anymore.

Doctrine Hydration Module
=========================

[](#doctrine-hydration-module)

Supported features
==================

[](#supported-features)

- 5.0.x: Upgrade to Laminas and requires PHP 7.4+
- 4.0.x: Contains zend-servicemanager &gt;=3.3.2 support requiring PHP 5.6+.
- 3.0.x: Contains zend-servicemanager &gt;=3 support requiring PHP 5.6+.
- 2.0.x: Contains zend-hydrator support requiring PHP 5.6+.
- 1.0.x: Contains zend-stdlib &lt;2.7 support requiring PHP 5.4+.

Make sure to commit on the correct branch if you want your changes to get merged into the project.

Installation
============

[](#installation)

Add to composer.json
--------------------

[](#add-to-composerjson)

```
composer require phpro/zf-doctrine-hydration-module

```

Add to application config
-------------------------

[](#add-to-application-config)

```
return array(
    'modules' => array(
        'Phpro\\DoctrineHydrationModule',
        // other libs...
    ),
    // Other config
);
```

### Hydrator configuration

[](#hydrator-configuration)

```
return array(
    'doctrine-hydrator' => array(
        'hydrator-manager-key' => array(
            'entity_class' => 'App\Entity\EntityClass',
            'object_manager' => 'doctrine.objectmanager.key.in.servicelocator',
            'by_value' => true,
            'use_generated_hydrator' => true,
            'naming_strategy' => 'custom.naming.strategy.key.in.servicemanager',
            'hydrator' => 'custom.hydrator.key.in.hydratormanager',
            'strategies' => array(
                'fieldname' => 'custom.strategy.key.in.servicemanager',
            ),
            'filters' => array(
                'custom_filter_name' => array(
                    'condition' => 'and', // optional, default is 'or'
                    'filter'    => 'custom.hydrator.filter.key.in.servicemanager',
                ),
            ),
        ),
    ),
);
```

**`entity_class`**

This property is used to specify the class of the entity that will be hydrated. You need to make sure that this entity is a mapped doctrine class.

**`object_manager`**

You can specify which object manager you want to use for the hydrator. The value is the key of the desired object manager in the service manager.

**`by_value`**

Specify if you want the hydrator to hydrate the entity by value or by reference.

**`use_generated_hydrator`**

This property will only be used with mongoDB ODM and will use the generated hydrators instead of the Doctrine Module Hydrator. Strategies will not work when this option is set to `true`.

**`naming_strategy`**

You can use a custom naming strategy for the hydrator. Specify the key of the naming strategy in the service manager. Note that this naming strategy needs to implement `NamingStrategyInterface`.

**`hydrator`**You can use a custom hydrator instead of the default `DoctrineObject` hydrator. Make sure this hydrator implements `HydratorInterface`.

**`strategies`**

It is possible to customize the hydration strategy of specific properties. Configure the property you want to customize with the key of the strategy in the service manager; Note that this strategy needs to implement `StrategyInterface`.

**`filters`**

This property can be used to apply filters on the Hydrator. You can specify a list of custom filters by defining the key of the filter in the service manager and the filter condition as described in the hydrator filter documentation. Note that this filter needs to implement `FilterInterface`.

From here on, you can get the hydrator by calling `get('hydrator-manager-key')` on the HydratorManager.

Custom strategies:
==================

[](#custom-strategies)

MongoDB ODM
-----------

[](#mongodb-odm)

- DateTimeField: Used for DateTime objects
- DefaultRelation: Leave the relation AS-IS. Does not perform any modifications on the field.
- EmbeddedCollection: Used for embedded collections
- EmbeddedField: Used for embedded fields
- ReferencedCollection: Used for referenced collections
- ReferencedField: Used for referenced fields.
- EmbeddedReferenceCollection: This is a custom strategy that can be used in an API to display all fields in a referenced object. The hydration works as a regular referenced object.
- EmbeddedReferenceField: This is a custom strategy that can be used in an API to display all fields in a referenced object. The hydration works as a regular referenced object.

Custom Filters
==============

[](#custom-filters)

Custom filters allow you to fine-tune the results of the hydrator's `extract` functionality by determining which fields should be extracted.

To configure custom filters:

```
return array(
    'doctrine-hydrator' => array(
        'custom-hydrator' => array(
            // other config
            'filters' => array(
                'custom.filter.name' => array(
                    'condition' => 'and', //optional, default: FilterComposite::CONDITION_OR,
                    'filter' => 'custom.filter', // a name in the Service Manager
                ),
            ),
        ),
    ),
);
```

In this example configuration, the hydrator factory will retrieve `custom.filter` from the Service Manager and inject it as a filter into the hydrator. The filter must implement `Zend\Hydrator\Filter\FilterInterface`.

The service's `filter($fieldName)` function will be called by the hydrator during `extract` and the field name being extracted will be passed as an argument. The `filter()` function must return a truthy value: if `true` then the field will NOT be extracted.

Override hydrator:
==================

[](#override-hydrator)

If the standard DoctrineHydrator is not flexible enough, you can set a custom `hydrator`. This allows you to use an extended DoctrineHydrator or another existing hydrator, and configure it with this module. This setting will override `use_generated_hydrator`.

```
return array(
    'doctrine-hydrator' => array(
        'custom-hydrator' => array(
            // other config
            'hydrator' => 'Zend\Hydrator\ArraySerializable'
        ),
    ),
);
```

Testing
=======

[](#testing)

This package is fully tested with Cs fixer and PhpUnit. The MongoDB tests require mongodb to be installed on your machine. You can skip these tests by adding a testsuite to the command:

```
# Php coding standards:
# (The files are loaded according to the PSR-4 standard. The PSR-0 fix will fail!)
./vendor/bin/php-cs-fixer fix . --dry-run  --fixers=-psr0

# Phpunit:
./vendor/bin/phpunit

# Testing one testsuite:
./vendor/bin/phpunit --testsuite="Main"
./vendor/bin/phpunit --testsuite="ODM"
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance42

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 75.1% 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 ~216 days

Recently: every ~188 days

Total

19

Last Release

473d ago

Major Versions

0.1.6 → v2.0.02016-06-14

v2.0.1 → v3.0.02016-10-05

v3.0.0 → v4.0.02018-10-25

v4.1.0 → v5.0.02023-01-02

4.0.x-dev → 5.2.02025-01-24

PHP version history (5 changes)0.1.5PHP &gt;=5.3.23

v3.0.0PHP ^5.6 || ^7.0

v5.0.0PHP ^7.4 || ^8.0 || ^8.1

v5.1.0PHP ^7.4 || ^8.0 || ^8.1 || ^8.2

5.0.x-devPHP ^7.4 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![veewee](https://avatars.githubusercontent.com/u/1618158?v=4)](https://github.com/veewee "veewee (139 commits)")[![michalbundyra](https://avatars.githubusercontent.com/u/7423207?v=4)](https://github.com/michalbundyra "michalbundyra (12 commits)")[![datasage](https://avatars.githubusercontent.com/u/826651?v=4)](https://github.com/datasage "datasage (11 commits)")[![TomHAnderson](https://avatars.githubusercontent.com/u/493920?v=4)](https://github.com/TomHAnderson "TomHAnderson (8 commits)")[![boukeversteegh](https://avatars.githubusercontent.com/u/53926?v=4)](https://github.com/boukeversteegh "boukeversteegh (6 commits)")[![alcaeus](https://avatars.githubusercontent.com/u/383198?v=4)](https://github.com/alcaeus "alcaeus (2 commits)")[![matwright](https://avatars.githubusercontent.com/u/4989280?v=4)](https://github.com/matwright "matwright (1 commits)")[![fabiocarneiro](https://avatars.githubusercontent.com/u/1375034?v=4)](https://github.com/fabiocarneiro "fabiocarneiro (1 commits)")[![phpboyscout](https://avatars.githubusercontent.com/u/175238?v=4)](https://github.com/phpboyscout "phpboyscout (1 commits)")[![thomasvargiu](https://avatars.githubusercontent.com/u/732012?v=4)](https://github.com/thomasvargiu "thomasvargiu (1 commits)")[![dorongutman](https://avatars.githubusercontent.com/u/719298?v=4)](https://github.com/dorongutman "dorongutman (1 commits)")[![tom-pryor](https://avatars.githubusercontent.com/u/1273529?v=4)](https://github.com/tom-pryor "tom-pryor (1 commits)")[![Bilge](https://avatars.githubusercontent.com/u/470626?v=4)](https://github.com/Bilge "Bilge (1 commits)")

---

Tags

laminasdoctrinehydrator

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/thomasvargiu-laminas-doctrine-hydration-module/health.svg)

```
[![Health](https://phpackages.com/badges/thomasvargiu-laminas-doctrine-hydration-module/health.svg)](https://phpackages.com/packages/thomasvargiu-laminas-doctrine-hydration-module)
```

###  Alternatives

[doctrine/doctrine-orm-module

Laminas Module that provides Doctrine ORM functionality

4407.3M293](/packages/doctrine-doctrine-orm-module)[doctrine/doctrine-module

Laminas Module that provides Doctrine basic functionality required for ORM and ODM modules

3957.9M116](/packages/doctrine-doctrine-module)[doctrine/doctrine-laminas-hydrator

Doctrine hydrators for Laminas applications

362.8M19](/packages/doctrine-doctrine-laminas-hydrator)[doctrine/doctrine-mongo-odm-module

Laminas Module which provides Doctrine MongoDB ODM functionality

86676.6k35](/packages/doctrine-doctrine-mongo-odm-module)[orbitale/array-fixture

A Doctrine Data Fixture service based on PHP arrays.

1636.7k](/packages/orbitale-array-fixture)[laminas-api-tools/api-tools-doctrine

Laminas API Tools Doctrine module

10633.9k5](/packages/laminas-api-tools-api-tools-doctrine)

PHPackages © 2026

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