Download the PHP package noc-med/zf-doctrine-hydration-module without Composer
On this page you can find all versions of the php package noc-med/zf-doctrine-hydration-module. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package zf-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 application config
Hydrator configuration
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:
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 allow you to fine-tune the results of the hydrator's extract
functionality by determining which fields should be extracted.
To configure custom filters:
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:
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
.
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:
All versions of zf-doctrine-hydration-module with dependencies
doctrine/common Version >=2.1
zendframework/zend-modulemanager Version 2.*
zendframework/zend-servicemanager Version 2.*
zendframework/zend-stdlib Version 2.*
doctrine/doctrine-module Version >=0.8.0
doctrine/instantiator Version ~1.0.4