GithubHelp home page GithubHelp logo

rakesh-mohanta / zf-doctrine-hydration-module Goto Github PK

View Code? Open in Web Editor NEW

This project forked from phpro/zf-doctrine-hydration-module

0.0 2.0 0.0 304 KB

Configurable Doctrine hydrators for ZF2

zf-doctrine-hydration-module's Introduction

Build status

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

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

Add to application config

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

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, 
            'strategies' => [
                'fieldname' => 'custom.strategy.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:

MongoDB ODM

  • DateTimeField: Used for DateTime objects
  • 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.

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:
./vendor/bin/php-cs-fixer fix . --dry-run

# Phpunit:
./vendor/bin/phpunit -c"tests/phpunit.xml"

# Testing one testsuite:
./vendor/bin/phpunit -c"tests/phpunit.xml" --testsuite="Main"
./vendor/bin/phpunit -c"tests/phpunit.xml" --testsuite="ODM"

zf-doctrine-hydration-module's People

Contributors

veewee avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.