PHPackages                             noc-med/zf-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. noc-med/zf-doctrine-hydration-module

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

noc-med/zf-doctrine-hydration-module
====================================

Doctrine hydrators for ZF2

0.1.5(11y ago)017MITPHPPHP &gt;=5.3.23

Since May 22Pushed 10y ago1 watchersCompare

[ Source](https://github.com/nocvp/zf-doctrine-hydration-module)[ Packagist](https://packagist.org/packages/noc-med/zf-doctrine-hydration-module)[ RSS](/packages/noc-med-zf-doctrine-hydration-module/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (11)Versions (6)Used By (0)

[![Build status](https://camo.githubusercontent.com/a6213ad9f1f7969c3f0e57d808517a8c75c355f17ebe914d4896971fe3126122/68747470733a2f2f6170692e7472617669732d63692e6f72672f706870726f2f7a662d646f637472696e652d687964726174696f6e2d6d6f64756c652e737667)](http://travis-ci.org/phpro/zf-doctrine-hydration-module)

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

[](#doctrine-hydration-module)

This module provides a configurable way to create new doctrine hydrators. By using the configurable API, it is easy to create a custom hydrator for any use case you want.

For ORM, the basic hydrator from the doctrine module is being used. It is possible to configure your own strategies for complex objects like referenced entities.

For MongoDB ODM, a specific hydrator is added. This hydrator will be able to handle Referenced documents and Embedded Documents. It is also possible to hydrate advanced documents with discriminator maps.

\#Installation

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

[](#add-to-composerjson)

```
"phpro/doctrine-hydration-module": "dev-master"

```

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',
                ),
            ),
        ),
    ),
);
```

use\_generated\_hydrator 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`.

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\Stdlib\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\Stdlib\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

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.4% 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 ~47 days

Total

6

Last Release

4135d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cd83d6b6c035e0082e898195d02aa9fb561d10be79e5a6946b8815be8bc33f8?d=identicon)[semihs](/maintainers/semihs)

---

Top Contributors

[![veewee](https://avatars.githubusercontent.com/u/1618158?v=4)](https://github.com/veewee "veewee (88 commits)")[![boukeversteegh](https://avatars.githubusercontent.com/u/53926?v=4)](https://github.com/boukeversteegh "boukeversteegh (6 commits)")[![TomHAnderson](https://avatars.githubusercontent.com/u/493920?v=4)](https://github.com/TomHAnderson "TomHAnderson (4 commits)")[![semihs](https://avatars.githubusercontent.com/u/4303177?v=4)](https://github.com/semihs "semihs (3 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)")

---

Tags

doctrinehydratorzf2

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/noc-med-zf-doctrine-hydration-module/health.svg)

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

###  Alternatives

[hounddog/doctrine-data-fixture-module

Zend Framework 2 Module that provides Doctrine Data-Fixture functionality

37335.4k9](/packages/hounddog-doctrine-data-fixture-module)[mamuz/mamuz-blog

Provides blog feature for ZF2 with Doctrine

101.1k1](/packages/mamuz-mamuz-blog)

PHPackages © 2026

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